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);
    }
相关推荐
l1t19 小时前
PostgreSQL pg_clickhouse插件的安装和使用
数据库·clickhouse·postgresql·插件
雨雨雨雨雨别下啦19 小时前
Spring AOP概念
java·后端·spring
on the way 12319 小时前
day04-Spring之Bean的生命周期
java·后端·spring
阿蒙Amon19 小时前
JavaScript学习笔记:14.类型数组
javascript·笔记·学习
代码笔耕19 小时前
面向对象开发实践之消息中心设计(二)
java·后端·架构
古德new19 小时前
openFuyao多样化算力使能:技术实现原理与开发者集成指南
服务器·数据库·安全
惊鸿.Jh19 小时前
高频SQL50题(基础版)解析(I)
数据库
sone1213819 小时前
Oracle 12c实验3:实验步骤的SQL语句
数据库·sql·oracle
XFF不秃头19 小时前
力扣刷题笔记-下一个排列
c++·笔记·算法·leetcode