//首先注入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
相关推荐
清幽竹客5 小时前
redis 进行缓存实战-18diving deep5 小时前
springboot集成日志配置文件源码云商6 小时前
基于 SpringBoot + Vue 的海滨体育馆管理系统设计与实现JWenzz16 小时前
Redis删除策略蚊子爱喝水7 小时前
Redis 8.0 新增数据结构深度解析:从核心功能到生态重构Uranus^8 小时前
深入解析Spring Boot与Spring Cloud在微服务架构中的实践与应用向上的车轮9 小时前
Spring Boot微服务架构(一):如何拆分?如何将CRM系统拆解为多个微服务构建?NAMELZX10 小时前
解决 IntelliJ IDEA 配置文件中文被转义问题草海桐10 小时前
Redis 详解