美文网首页
SpringDataRedis使用说明及Springboot使用

SpringDataRedis使用说明及Springboot使用

作者: 過眼云烟 | 来源:发表于2019-06-05 17:14 被阅读0次
SpringDataRedis使用说明
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向redis里存入数据和设置缓存时间
stringRedisTemplate.opsForValue().get("test")//根据key获取缓存中的val
stringRedisTemplate.boundValueOps("test").increment(-1);//val做-1操作
stringRedisTemplate.boundValueOps("test").increment(1);//val +1
stringRedisTemplate.getExpire("test")//根据key获取过期时间
stringRedisTemplate.getExpire("test",TimeUnit.SECONDS)//根据key获取过期时间并换算成指定单位
stringRedisTemplate.delete("test");//根据key删除缓存
stringRedisTemplate.hasKey("546545");//检查key是否存在,返回boolean值
stringRedisTemplate.expire("red_123",1000 , TimeUnit.MILLISECONDS);//设置过期时间
stringRedisTemplate.opsForSet().add("red_123", "1","2","3");//向指定key中存放set集合
stringRedisTemplate.opsForSet().isMember("red_123", "1")//根据key查看集合中是否存在指定数据
stringRedisTemplate.opsForSet().members("red_123");//根据key获取set集合
SpringBoot Cach缓存使用

存储在java虚拟机中,方法简单,方法较少
1,在application启动类上加注解 @EnableCathing
2, 在使用的方法上加上@Cacheable (value="gathering",key="#id") value代表一个大集合,可以存很多key,key="#id",代表将id存入里面gathering里面 //这种写法代表以后优先从缓存中取

相关文章

网友评论

      本文标题:SpringDataRedis使用说明及Springboot使用

      本文链接:https://www.haomeiwen.com/subject/isysxctx.html