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);
    }
相关推荐
TL滕5 分钟前
从0开始学算法——第三天(数据结构的操作)
数据结构·笔记·学习·算法
云边有个稻草人6 分钟前
国产化数据库标杆!金仓以五大技术优势,筑牢电力行业数字基石
数据库·金仓数据库·kes
v***56511 分钟前
常见的 Spring 项目目录结构
java·后端·spring
j***121513 分钟前
MySQL如何执行.sql 文件:详细教学指南
数据库·mysql
zhouyunjian15 分钟前
10-ScheduledThreadPool应用与源码分析
运维·服务器·数据库
叫致寒吧17 分钟前
Mysql
数据库·mysql
超频化石鱼18 分钟前
使用Postman访问siliconflow大模型接口
java·postman·ai编程
f***453218 分钟前
SpringCloud篇(配置中心 - Nacos)
java·spring·spring cloud
b***666119 分钟前
Spring Framework 中文官方文档
java·后端·spring
凯子坚持 c24 分钟前
《openGauss向量数据库_助力企业RAG应用落地实践》
数据库