redis存取list集合

embedded/2025/3/1 2:47:15/

list_4">一 、存取为list类型

  1. @RestController

  2. @RequestMapping(“/test”)

  3. @Slf4j

  4. publicclassTestController

  5. @Autowired

  6. private RedisTemplate redisTemplate;

  7. @ApiOperation(“redis-savelist”)

  8. @PostMapping(“/redis/save/list”)

  9. public void redisSaveList() {

  10. Listlist = getPersonList();

  11. //清空

  12. while (redisTemplate.opsForList().size(“oowwoo”) >0){

  13. redisTemplate.opsForList().leftPop(“oowwoo”);

  14. }

  15. //存储

  16. redisTemplate.opsForList().rightPushAll(“oowwoo”,list);

  17. //取出

  18. List oowwoo = redisTemplate.opsForList().range(“oowwoo”,0,-1);

  19. log.info(“>>>>>>>>>>>>>>>list = {}”, oowwoo.toString());

  20. Iterator it = oowwoo.iterator();

  21. while(it.hasNext()){

  22. Person p = it.next();

  23. log.info(“person = {}”, p.toString());

  24. }

  25. }

  26. privateList getPersonList() {

  27. Person p1 =new Person();

  28. p1.setId(1L);

  29. p1.setName(“张一”);

  30. p1.setAge(11);

  31. Person p2 =new Person();

  32. p2.setId(2L);

  33. p2.setName(“张二”);

  34. p2.setAge(22);

  35. Person p3 =new Person();

  36. p3.setId(3L);

  37. p3.setName(“张三”);

  38. p3.setAge(33);

  39. Listlist =new ArrayList<>();

  40. list.add(p1);

  41. list.add(p2);

  42. list.add(p3);

  43. returnlist;

  44. }

  45. }

listjson_103">二 、将list转为json对象存取

  1. import com.alibaba.fastjson.JSON;

  2. import com.alibaba.fastjson.JSONObject;

  3. @Autowired

  4. private StringRedisTemplate stringRedisTemplate;

  5. //存

  6. List businessIdList = eeFreecarriageShopService.selectBusinessIdInPromotion();

  7. stringRedisTemplate.opsForValue().set(RedisConstants.FREECARRIAGE_BUSINESSIDLIST, JSON.toJSON(businessIdList).toString());

  8. //取

  9. String businessJsonArray = stringRedisTemplate.opsForValue().get(RedisConstants.FREECARRIAGE_BUSINESSIDLIST);

  10. List businessIdList = JSONObject.parseArray(businessJsonArray,Long.class);

java 用redisTemplate 的 Operations存取list集合


http://www.ppmy.cn/embedded/168943.html

相关文章

【软考-架构】1.1、计算机硬件-CPU校验码

计算机硬件组成 中央处理单元 运算器 算术逻辑单元ALU&#xff08;实现对数据的算术和逻辑运算&#xff09;;累加寄存器AC&#xff08;运算结果或源操作数的存放区&#xff09;;数数据缓冲寄存器DR&#xff08;暂时存放内存的指令或数据&#xff09;;状态条件寄存器PSW&#x…

STM32--SPI通信讲解

前言 嘿&#xff0c;小伙伴们&#xff01;今天咱们来聊聊STM32的SPI通信。SPI&#xff08;Serial Peripheral Interface&#xff09;是一种超常用的串行通信协议&#xff0c;特别适合微控制器和各种外设&#xff08;比如传感器、存储器、显示屏&#xff09;之间的通信。如果你…

DeepSeek模型昇腾部署优秀实践

2024年12月26日&#xff0c;DeepSeek-V3横空出世&#xff0c;以其卓越性能备受瞩目。该模型发布即支持昇腾&#xff0c;用户可在昇腾硬件和MindIE推理引擎上实现高效推理&#xff0c;但在实际操作中&#xff0c;部署流程与常见问题困扰着不少开发者。本文将为你详细阐述昇腾 De…

React表单状态管理深度解析:Form.useWatch与onChange技术选型指南

React表单状态管理深度解析&#xff1a;Form.useWatch与onChange技术选型指南 一、核心机制对比 1.1 底层原理图解 #mermaid-svg-YteLGfOvYI1ayxbC {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-YteLGfOvYI1ayxb…

ubuntu:桌面版磁盘合并扩容

下载gparted磁盘编辑器 apt-get install gparted 打开gparted 更改目标分区大小 当遇到这个报错时&#xff0c;需要在命令行执行原分区的挂载指令 查看该分区信息 记住该目录&#xff0c;并在命令行执行 mount -o remount -rw /# 示例&#xff1a;mount -o remount -rw /v…

【javaEE】计算机是如何工作的(基础常识)

1.❤️❤️前言~&#x1f973;&#x1f389;&#x1f389;&#x1f389; Hello, Hello~ 亲爱的朋友们&#x1f44b;&#x1f44b;&#xff0c;这里是E绵绵呀✍️✍️。 如果你喜欢这篇文章&#xff0c;请别吝啬你的点赞❤️❤️和收藏&#x1f4d6;&#x1f4d6;。如果你对我的…

一、IDE集成DeepSeek保姆级教学(安装篇)

一、JetBrains IDEA 中安装教学 第一步&#xff1a;事先准备 支持系统&#xff1a;Windows 7 ~ Windows 11、Linux、macOS&#xff1b;下载并安装兼容的 JetBrains IDEA 2021.2 及以上版本&#xff0c;推荐使用2024.1及以上的版本以获取最佳兼容性&#xff1b;安装 Python 3.…

数据驱动未来!天合光能与永洪科技携手开启数字化新篇章

在信息化时代的今天&#xff0c;企业间的竞争早就超越了传统产品与服务的范畴&#xff0c;新的核心竞争力即——数据处理能力和信息技术的应用。作为数据技术领域的领军者&#xff0c;永洪科技凭借其深厚的技术积累和丰富的行业经验&#xff0c;成功助力天合光能实现数字化升级…