//首先注入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
相关推荐
霸道流氓气质7 小时前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南于先生吖8 小时前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解小小工匠8 小时前
Redis - 事务机制:能实现 ACID 属性吗Flittly8 小时前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手星落zx10 小时前
Spring Boot 多模型集成:优雅调用全球主流大模型一杯奶茶¥11 小时前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统进阶的小名12 小时前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题taocarts_bidfans12 小时前
反向海淘跨境缓存架构优化:taocarts Redis分层缓存实战技术我登哥MVP13 小时前
SpringCloud Alibaba 核心组件解析:服务链路追踪范什么特西13 小时前
Spring boot细节