日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

springboot 的 RedisTemplate 的 execute 和 executePipelined 功能的区别redis

發布時間:2025/3/12 数据库 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot 的 RedisTemplate 的 execute 和 executePipelined 功能的区别redis 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。