StringRedisTemplate常用API

转载自网络: 

 

//向redis里存入数据和设置缓存时间
stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);  
 
//val做-1操作
stringRedisTemplate.boundValueOps("test").increment(-1);  
 
//根据key获取缓存中的val
stringRedisTemplate.opsForValue().get("test")
 
//val +1  
stringRedisTemplate.boundValueOps("test").increment(1);
 
//根据key获取过期时间  
stringRedisTemplate.getExpire("test")
 
//根据key获取过期时间并换算成指定单位
stringRedisTemplate.getExpire("test",TimeUnit.SECONDS)
 
//根据key删除缓存
stringRedisTemplate.delete("test");  
 
//检查key是否存在,返回boolean值
stringRedisTemplate.hasKey("546545");  
 
//向指定key中存放set集合
stringRedisTemplate.opsForSet().add("red_123", "1","2","3");
 
//设置过期时间
stringRedisTemplate.expire("red_123",1000 , TimeUnit.MILLISECONDS);
 
//根据key查看集合中是否存在指定数据  
stringRedisTemplate.opsForSet().isMember("red_123", "1")
 
//根据key获取set集合
stringRedisTemplate.opsForSet().members("red_123");

posted @   fy_qxl  阅读(4562)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示