//首先注入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 小时前
基于SpringBoot的健康食谱管理系统的设计与实现(源码+文档+讲解视频)骇客野人3 小时前
Springboot 的 配置文件 application.yml 和 bootrap.yml 的由来和作用xcl09253 小时前
幼儿托管系统开发实战:从需求分析到部署上线全指南步行cgn3 小时前
Spring Boot 中的 YAML 完全指南csdn2015_3 小时前
java springboot项目,接收到的参数多个逗号摇滚侠4 小时前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis MyBatis 简单开发 阅读笔记 39Mr.敦的私房菜4 小时前
【SpringEvent】Spring Boot / Spring Framework 事件大全程序员阿明4 小时前
spring boot4+springAI 2加redis多轮对话存储Mr.敦的私房菜4 小时前
【SpringBoot请求记录】Spring Boot Actuator 自定义记录 HTTP 服务请求java1234_小锋4 小时前
MyBatis-Plus 3.5.15 已全面支持 Spring Boot 4.0 及 Jackson 3.0