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. python3.7源码分析-字典
  2. 12JavaScript中的内置对象
  3. 阮一峰网络日志 第41期 2019年01月25日
  4. 硬肝!超详细的Python文件操作知识
  5. 蛮力法在查找算法中的应用(JAVA)--顺序查找
  6. docker mysql数据库初始化_如何在Mysql的Docker容器启动时初始化数据库
  7. leetcode 354. 俄罗斯套娃信封问题(二维排序有关)
  8. YJX_Driver_031_再谈SSDT_HOOK驱动保护原理
  9. 常用的Linux命令行文本处理工具总结
  10. AVPlayer 音视频缓存方案
  11. html金额自动换算成大写,JavaScript实现将人民币小写金额自动转换成大写的方法...
  12. CCYYMMDD时间格式
  13. TCP全连接端口扫描器
  14. 小白学编程必备的三大网站
  15. 微信小程序开发:Java后台MySQL数据库微信小程序页面
  16. python 使用爬虫下载京东图片
  17. 超好用的清理软件Wise Disk Cleaner X
  18. 超牛逼!这款开源性能监控系统真强大~
  19. python三方库—pywebio
  20. 技术领导力之路 - 安全感

热门文章

  1. 事物 php,什么是php事务
  2. composer 检查镜像_检查N元树中的镜像
  3. Java包hashCode()方法及示例
  4. Java BufferedWriter close()方法与示例
  5. 电子增稳云台_揭秘Dobby自拍无人机,电子增稳是黑科技?
  6. 人生苦短python作伴_“人生苦短,我用Python”
  7. Java ObjectInputStream readDouble()方法与示例
  8. 阅读源码的 4 个绝技,我必须分享给你!
  9. Oracle数据库版本维护支持结束时间表以及数据库版本发行时间表
  10. ASP.NET MVC中使用Autofac实现简单依赖注入