1.executespring

如下是 springboot 官网原文:springboot

Redis provides support for transactions through the multi, exec, and discard commands. These operations are
available on RedisTemplate, however RedisTemplate is not guaranteed to execute all operations in the
transaction using the same connection.ideSpring Data Redis provides the SessionCallback interface for use when multiple operations need to be performed
with the same connection, as when using Redis transactions. For example:

//execute a transaction
List txResults = redisTemplate.execute(new SessionCallback<List>() {
public List execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForSet().add(“key”, “value1”); // This will contain the results of all ops in the transaction return operations.exec(); } });

翻译下来就是:code

Redis 经过multi, exec, discard 操做提供事务支持. RedisTemplate 也一样支持这些操做, 然而 RedisTemplate 不保证在同一个链接中执行事务中的全部操做.orm

当使用 redis 的事务的时候, Spring Data Redis 提供 SessionCallback 的接口支持多个操做的执行都在同一个链接中.

2.Pipeline

Redis provides support for pipelining, which involves sending multiple commands to the server without waitingfor the replies and then reading the replies in a single step. Pipelining can improve performance when you need to send several commands in a row, such as adding many elements to the same List.Spring Data Redis provides several RedisTemplate methods for executing commands in a pipeline. If you don't
care about the results of the pipelined operations, you can use the standard execute method, passing true for
the pipeline argument. The executePipelined methods will execute the provided RedisCallback or SessionCallback
in a pipeline and return the results. For example:

Redis 提供 pipelining(管道) 的支持, 它能够发送多条指令到 redis服务端 而不用等待服务端的回复 而且 读取服务端的回复在一步操做中. 当你须要连续发送多条命令的时候 Pipelining(管道) 能够改善性能, such as 添加多个元素到同一个list中.

Spring Data Redis 提供几个 RedisTemplate 的方法支持在一个 pipeline(管道) 中执行多个指令.若是不关注管道操做的结果, 能够使用标准的execute方法, 传递true 的pipeline参数.

executePipelined 方法会执行 RedisCallback or SessionCallback 的回调方法以返回结果.

//pop a specified number of items from a queue
List results = stringRedisTemplate.executePipelined(new RedisCallback() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisConnection stringRedisConn = (StringRedisConnection)connection;
for(int i=0; i< batchSize; i++) { stringRedisConn.rPop(“myqueue”); } return null; } });

在redis官网中: ( 官网地址: https://redis.io/topics/pipelining )

从 It’s not just a matter of RTT 这一段开始, pipeline不单单是不用等待回复时间(RTT)就能够持续的发送指令. 而且使用 pipeline的时候, redis用一个read()操做读取多个指令,而且 经过一个 write() 传递多个结果.最终的结果, 使用 pipeline 的效率甚至能至关于不使用pipeline的 10 倍.

(来张官网的图)

springboot 的 RedisTemplate 的 execute 和 executePipelined 功能的区别redis相关推荐

  1. springboot系列——redisTemplate和stringRedisTemplate对比、redisTemplate几种序列化方式比较

    文章目录 一.redisTemplate和stringRedisTemplate对比 1.StringRedisTemplate 2.RedisTemplate 二.redisTemplate序列化方 ...

  2. SpringBoot整合redisTemplate获取自增主键

    SpringBoot整合redisTemplate获取自增主键 在Spring Boot应用程序中,我们可以使用Redis作为缓存或数据存储.当我们使用Redis存储数据时,我们可能需要使用自增主键. ...

  3. 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能...

    springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...

  4. springboot使用redisTemplate 报错:APP FAILED TO START Field template in required a single bean redis工具类

    springboot使用redisTemplate 报错: template in com.j.ssm.tool.RedisUtil required a single bean, but 2 wer ...

  5. 【vue+springboot】excel模板下载、导入功能实现

    基于VUE+SpringBoot实现excel模板下载.导入功能 背景 最近在工作中经常遇到批量导入的功能,而且前端还要提示导入成功几条.失败几条.哪一条数据重复.是哪一条导入的数据出现问题等,抽空写 ...

  6. SpringBoot 集成FluentMyBatis 框架之集成分页功能

    本文基于上一篇:SpringBoot 集成FluentMyBatis 框架之完善 SpringBoot 集成FluentMyBatis 框架之集成分页功能 FluentMyBatis 官方分页 官方提 ...

  7. Spring-boot通过redisTemplate使用redis(无须手动序列化)

    转载请注明出处 : Spring-boot通过redisTemplate使用redis(无须手动序列化) redisTemplate的一些操作可以参考下面俩篇文章 http://blog.csdn.n ...

  8. SpringBoot集成RedisTemplate

    SpringBoot集成RedisTemplate 1. 导入依赖 <!--Redis--><dependency><groupId>org.springframe ...

  9. 智慧课堂app(一)Flutter+springboot 实现考勤码+gps考勤签到功能

    Flutter+springboot实现考勤码+gps考勤签到功能 实现步骤和思路: 设计 发布考勤任务 签到考勤 环境准备 后端步骤: 1.教师发布考勤任务接口 2.rabbitmq收到教师发布考勤 ...

最新文章

  1. 呵呵,你开心就好!——AI向杠精宣战
  2. Xamarin Essentials教程磁力计Magnetometer
  3. anguarjs 图片预览_Text to Image Converter(文字转图片软件)下载-Text to Image Converter(文字转图片软件)v1.5绿色版下载...
  4. 如何使用idea远程debug调试代码详解
  5. 《P5R》的反派设计有什么可取之处?
  6. arch linux键盘布局,Arch Linux的安装、配置、优化及美化(一)
  7. 面对SDN/NFV部署挑战 网络厂商能做什么?
  8. Java校招笔试题-Java基础部分(四)
  9. 山东酒桌上的称谓座次以及基本礼仪
  10. 论文赏析[EMNLP18]用控制任务来设计并解释探测任务
  11. asp判断是否移动端_ASP判断当前访问的是PC端还是移动设备端
  12. 卡尔曼滤波原理详解及系统模型建立(simulink)
  13. JS中三个点(...)是什么鬼?
  14. leet code No1
  15. c语言间接级别不同_一个超复杂的间接递归——C语言初学者代码中的常见错误与瑕疵(6)...
  16. OSSH免费版华为Portal
  17. 自然辩证法问题思考范围(开卷可用)
  18. 灵隐寺招聘员工:没有KPI,佛系上班,四点半下班……
  19. 微服务之API网关:Kong:概要与安装
  20. Axure 交互学习1 基础页面跳转、鼠标悬停样式

热门文章

  1. mysql将查询数据另存
  2. c ++查找字符串_C ++朋友功能| 查找输出程序| 套装1
  3. php映射,PHP实现路由映射到指定控制器
  4. mysql内置变量_MySQL常用内置变量
  5. 图片md5修改工具_如何修改视频和图片的MD5,用电脑自带的命令
  6. 一个websocket 可以多个页面创建吗_实战分享|给我一个Puppeteer,没有爬不了的网站
  7. 二层交换网络_网络中的第2层交换
  8. 线程池是如何执行的?拒绝策略有哪些?
  9. 漫画:Integer 竟然有 4 种比较方法?
  10. 缓存通用管理类 + 缓存 HttpContext.Current.Cache 和 HttpRuntime.Cache 的区别