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);
    }
相关推荐
顶点多余1 分钟前
Mysql--后端与前端关系
数据库·mysql
mygljx4 分钟前
【MySQL 的 ONLY_FULL_GROUP_BY 模式】
android·数据库·mysql
Andya_net11 分钟前
Spring | @EventListener事件机制深度解析
java·后端·spring
lang2015092824 分钟前
18 Byte Buddy 进阶指南:解锁 `@Pipe` 注解,实现灵活的方法转发
java·byte buddy
重庆小透明26 分钟前
【java基础篇】详解BigDecimal
java·开发语言
sunwenjian88627 分钟前
Springboot项目本地连接并操作MySQL数据库
数据库·spring boot·mysql
Navicat中国1 小时前
如何轻松创建存储过程 | Navicat 教程
数据库·存储过程·可视化·navicat
Mr. Cao code1 小时前
MySQL服务器配置与socket连接详解
服务器·数据库·mysql
Yupureki1 小时前
《MySQL数据库基础》1. 数据库基础
c语言·开发语言·数据库·c++·mysql·oracle·github
杰克尼2 小时前
苍穹外卖--day08
java·数据库·spring boot·mybatis·notepad++