//首先注入redisTemplate
@Autowired
private RedisTemplate<String, Object> redisTemplate;
//获取hash类型的ops
HashOperations<String, String, Object> stringObjectObjectHashOperations = redisTemplate.opsForHash();
//创建一个一个map并将一个对象的属性拆解进去
HashMap<String, Object> map = new HashMap<>();
map.put("username", user.getUsername());
map.put("password", user.getPassword());
map.put("tel", user.getTel());
map.put("address", user.getAddress());
map.put("imageFilename", user.getImageFilename());
map.put("email", user.getEmail());
map.put("coins", user.getCoins());
stringObjectObjectHashOperations.putAll(user.getId().toString(), map);
//为刚刚设置的key设置过期时间为6小时
redisTemplate.expire(user.getId().toString(), 6, TimeUnit.HOURS);
在项目中使用redisTemplate向redis添加hash类型数据
才艺のblog2024-05-08 23:37
相关推荐
小强库计算机毕业设计1 小时前
基于 Spring Boot + Vue3 的校园管理系统Amir_zy2 小时前
Redis测试方法全攻略:冒烟、压测与稳定性验证霸道流氓气质4 小时前
RedLock:Redis 分布式锁的高可用方案云烟成雨TD4 小时前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaegercsdn2015_4 小时前
springboot +mybatis 查询myql开启程序级别缓存chuan.bai5 小时前
Java RAG 实战(第 8 篇):Spring Boot RAG 查询 APIbreeze jiang5 小时前
Next.js App Router 父子组件 RSC 拆分实战:从 Redis Hash 到客户端交互的最小化边界vx-程序开发5 小时前
springboot旅游推介平台---附源码24175小蒜学长6 小时前
“喵汪联盟”宠物领养系统的设计与实现(代码+数据库+LW)xbgRS9 小时前
springboot的自动装配