//首先注入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
相关推荐
代码老y29 分钟前
Spring Boot + MyBatis + Vue:全栈开发中的最佳实践Q_Q19632884751 小时前
python+uniapp基于微信小程序的高校二手商品交易系统萌新小码农2 小时前
SpringBoot新闻项目学习day3--后台权限的增删改查以及权限管理分配Luffe船长3 小时前
springboot将文件插入到指定路径文件夹,判断文件是否存在以及根据名称删除码农开荒路4 小时前
Redis之缓存一致性武昌库里写JAVA4 小时前
VUE vuex深入浅出代码老y4 小时前
Spring Boot + MyBatis + Vue:从零到一构建全栈应用罗政5 小时前
小区物业管理系统源码+SpringBoot + Vue (前后端分离)YuTaoShao5 小时前
Java八股文——Redis「淘汰删除篇」vx Biye_Design5 小时前
SSM学生社团管理系统-计算机毕业设计源码75136