Spring Boot 2关于Redis的使用(3)

对RedisTemplate的理解

public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperations<K, V>, BeanClassLoaderAware {
    //操作普通键值对
	private @Nullable ValueOperations<K, V> valueOps;
	//操作list
	private @Nullable ListOperations<K, V> listOps;
	//操作set
	private @Nullable SetOperations<K, V> setOps;
	//操作sortedset
	private @Nullable ZSetOperations<K, V> zSetOps;
	//操作地理坐标信息
	private @Nullable GeoOperations<K, V> geoOps;
	//应用于基数计算
	private @Nullable HyperLogLogOperations<K, V> hllOps;
}
//针对key、value都是String的场景
public class StringRedisTemplate extends RedisTemplate<String, String> {
}

ValueOperations常用操作

stringRedisTemplate.opsForValue().set(key, value, second);
stringRedisTemplate.opsForValue().get(key);
stringRedisTemplate.opsForValue().multiSet(value);
stringRedisTemplate.opsForValue().multiSetIfAbsent(value);
stringRedisTemplate.opsForValue().multiGet(key);

ListOperations常用操作

stringRedisTemplate.opsForList().leftPushAll(key,value);
stringRedisTemplate.opsForList().rightPushAll(key,value);
stringRedisTemplate.opsForList().size(key);
stringRedisTemplate.opsForList().range(key, start, end);
stringRedisTemplate.opsForList().leftPop(key);
stringRedisTemplate.opsForList().rightPop(key);

SetOperations常用操作

stringRedisTemplate.opsForSet().add(key,value);
stringRedisTemplate.opsForSet().size(key);
stringRedisTemplate.opsForSet().members(key);

ZSetOperations常用操作

stringRedisTemplate.opsForZSet().add(key,value,score);
stringRedisTemplate.opsForZSet().zCard(key);
stringRedisTemplate.opsForZSet().count(key, min, max);
stringRedisTemplate.opsForZSet().rangeByScore(key, min, max, offset, count);
stringRedisTemplate.opsForZSet().rangeByScoreWithScores(key, min, max);

HashOperations常用操作

stringRedisTemplate.opsForHash().put(key, hashKey, value);
stringRedisTemplate.opsForHash().size(key);
stringRedisTemplate.opsForHash().get(key, hashKey);
stringRedisTemplate.opsForHash().values(key);
stringRedisTemplate.opsForHash().entries(key);

GeoOperations常用操作

stringRedisTemplate.opsForGeo().add(key,memberMap);
stringRedisTemplate.opsForGeo().hash(key,members);
stringRedisTemplate.opsForGeo().distance(key,member1,member2);

HyperLogLogOperations常用操作

stringRedisTemplate.opsForHyperLogLog().add(key,values);
stringRedisTemplate.opsForHyperLogLog().size(key);

源码位置
https://gitee.com/ceclar123/spring-boot-demo/tree/master/ch02

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值