redis批处理优化

1.为什么需要批处理

一个命令在网络传输的时间往往是远大于在redis中执行命令的时间的,如果每条命令都要逐条经历网络传输,耗时将会大大增加,我们不妨将命令多量少次的传输给redis,这样就大大减少了因为网络传输时间,大大提高的效率

2.如何进行批处理

2.1.单机模式下的批处理

2.2.集群模式下的批处理

这里spring已经给我们封装好了批处理的方法

java 复制代码
    @Test
    void testMSetInCluster() {
        Map<String,String> map = new HashMap<>(3);
        map.put("name","Rose");
        map.put("age","21");
        map.put("sex","Female");
        stringRedisTemplate.opsForValue().multiSet(map);    // 批处理方法

        List<String> strings = stringRedisTemplate.opsForValue().multiGet(Arrays.asList("name", "age", "sex"));
        strings.forEach(System.out::println);
    }
相关推荐
好奇的菜鸟9 分钟前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
tan180°10 分钟前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
巴伦是只猫29 分钟前
【机器学习笔记Ⅰ】13 正则化代价函数
人工智能·笔记·机器学习
DuelCode1 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
优创学社21 小时前
基于springboot的社区生鲜团购系统
java·spring boot·后端
幽络源小助理1 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
猴哥源码1 小时前
基于Java+springboot 的车险理赔信息管理系统
java·spring boot
Hello.Reader2 小时前
Redis 延迟排查与优化全攻略
数据库·redis·缓存
YuTaoShao2 小时前
【LeetCode 热题 100】48. 旋转图像——转置+水平翻转
java·算法·leetcode·职场和发展
Dcs3 小时前
超强推理不止“大”——手把手教你部署 Mistral Small 3.2 24B 大模型
java