//首先注入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
相关推荐
IT规划师15 分钟前
Redis 数据类型全解 - HyperLogLog:12 KB 估出亿级 UV(八)jktantan42 分钟前
注解式脱敏:用 Jackson 的 ContextualSerializer 做字段级策略(一)aiks_yuan15 小时前
Token 放 Redis 还是用 JWT:Java 实测验签和查 Redis 耗时,退出登录、改密码踢下线怎么做(jjwt 0.12 + Redis 7.2)露天赏雪15 小时前
第3篇:Sentinel熔断降级实战:大模型接口抖动时的服务兜底方案蜗牛8751 天前
为 Spring Boot 团队做一个 Elasticsearch 查询工作台:六种模式、语义补全与浏览器直连我不会起名字3221 天前
Redis 从 0 到 1(二十九):CPU 突然 100%——commandstats 定位法与 6 步排查链路我不会起名字3221 天前
Redis 从 0 到 1(二十八):Redis 抖一下,重试把它打挂了——超时/重试/熔断的 Go 封装养军博客1 天前
Spring Boot 3.x + Spring Security 6.x 整合 JWT 实战:jjwt 与 java-jwt 两种工具库详解我不会起名字3221 天前
Redis 从 0 到 1(三十):删了一半数据 RSS 不降——内存碎片与 activedefrag 观测txxzjmzlh1 天前
SpringBoot 统⼀功能处理