//首先注入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
相关推荐
Chengbei113 小时前
Redis 图形化综合检测工具:redis_tools_GUI,一键探测 + 利用cjy0001114 小时前
springboot的 nacos 配置获取不到导致启动失败及日志不输出问题sheji34165 小时前
【开题答辩全过程】以 基于springboot的校园失物招领系统为例,包含答辩的问题和答案lars_lhuan6 小时前
从键值数据库到Redis程序员阿伦7 小时前
璋㈤鏈虹殑Java澶у巶闈㈣瘯璁帮細浠嶴pring Boot鍒癒ubernetes锛�3杞湡棰樺叏瑙f瀽锛�wuyikeer7 小时前
Spring BOOT 启动参数zdl6869 小时前
springboot集成onlyoffice(部署+开发)可观测性用观测云9 小时前
SpringBootAI 接入观测云 MCP 最佳实践BUG胡汉三9 小时前
自建在线文档编辑服务:基于 Collabora CODE + Spring Boot + Vue 3 的完整实现gechunlian8810 小时前
Redis简介、常用命令及优化