[英]go-redis maxRetries doesn't work with redis pipeline
I am trying to use maxRetries
option of go-redis client.我正在尝试使用 go-redis 客户端的
maxRetries
选项。
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/go-redis/redis/v8"
)
func main() {
db := redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: []string{"localhost:6379"},
PoolTimeout: time.Duration(10) * time.Minute,
MaxRetries: 3,
MinRetryBackoff: 5 * time.Second,
MaxRetryBackoff: 5 * time.Second,
})
ctx := context.Background()
var i int64
/*for i = 0; i <= 10000; i += 100 {
time.Sleep(time.Second * 2)
fmt.Println("i : ", i)
test, err := db.HIncrBy(ctx, "testkv", "test", i).Result()
log.Println("Increment result ", test, err)
val, valerr := db.HGet(ctx, "testkv", "test").Result()
log.Println("The new value of test is ", val, valerr)
}*/
for i = 0; i <= 10000; i += 100 {
time.Sleep(time.Second * 2)
fmt.Println("i : ", i)
pipe := db.Pipeline()
testRes := pipe.HIncrBy(ctx, "testkv", "test", i)
valRes := pipe.HGet(ctx, "testkv", "test")
_, err := pipe.Exec(ctx)
pipe.Close()
log.Println("Pipe Err: ", err)
test, err := testRes.Result()
log.Println("Increment result ", test, err)
val, valerr := valRes.Result()
log.Println("The new value of test is ", val, valerr)
}
}
The above commented code is without pipeline.上面注释的代码没有管道。 In that case, while the loop is being executed if redis goes off then I see command's execution getting blocked until 15seconds (due to retry) and then the next command is executed.
在这种情况下,如果 redis 关闭,则在执行循环时我会看到命令的执行被阻塞直到 15 秒(由于重试),然后执行下一个命令。 Once, redis comes up, the loop continues with successful execution of the command.
一旦出现 redis,循环将继续并成功执行命令。 This blocking thing is not happening in case of the pipeline scenario.
在管道场景的情况下,不会发生这种阻塞情况。 Any help is appreciated.
任何帮助表示赞赏。 Thanks.
谢谢。
Per this issue cluster client doesn't retry on pipeline read timeouts , the retry policy does NOT apply to the pipeline.根据这个问题,集群客户端不会在管道读取超时时重试,重试策略不适用于管道。
The motivation was that we should not try to retry half of the pipeline, because it can be that user relies that all commands in pipeline are executed together once.
动机是我们不应该尝试重试管道的一半,因为用户可能依赖管道中的所有命令一起执行一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.