简体   繁体   English

go-redis maxRetries 不适用于 redis 管道

[英]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.

相关问题 如何在 go-redis 中从 client.Watch 函数运行非事务管道 - How to run non transaction pipeline from a client.Watch function in go-redis 下载 go-redis 包时报错找不到包“github.com/go-redis/redis/v8” - Error cannot find package "github.com/go-redis/redis/v8" when downloading go-redis package 无法编组,(实现 encoding.BinaryMarshaler)。 带有多个对象的 go-redis Sdd - Can't marshal, (implement encoding.BinaryMarshaler). go-redis Sdd with multiple objects 为什么不能用 go-redis 获得的值将字符串转换为 int? - Why can't convert string to int with value got by go-redis? 如何使用 go-redis/redis 包在 Go 中创建 Redis 事务? - How to create Redis Transaction in Go using go-redis/redis package? 如何将键数组传递给 go-redis 包中的 MGET func? - how to pass array of keys to MGET func in go-redis package? 带字符串字段的Go-Redis HMSet提供WRONGTYPE操作 - Go-Redis HMSet with string fields gives WRONGTYPE Operation Go + Redis - 教程入门不起作用 - Go + Redis - Tutorial Get Started doesn't work 使用不带WATCH的go-redis包实现流水线和事务到Redis集群 - Implementing pipelining and transaction both to a redis cluster using go-redis package without WATCH 如何从 golang go-redis 中的 redis.Cmder 获取价值? - How to get get value from redis.Cmder in golang go-redis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM