go-redis的maxRetries在使用redis pipeline时不起作用。

huangapple go评论88阅读模式
英文:

go-redis maxRetries doesn't work with redis pipeline

问题

我正在尝试使用go-redis客户端的maxRetries选项。

上面的代码是使用管道之前的注释代码。在这种情况下,当循环执行时,如果Redis关闭,我会看到命令的执行被阻塞,直到15秒后(由于重试),然后执行下一个命令。一旦Redis恢复,循环将继续成功执行命令。在使用管道的情况下,不会发生这种阻塞。如果有任何帮助,将不胜感激。谢谢。

英文:

I am trying to use maxRetries option of go-redis client.

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. Once, redis comes up, the loop continues with successful execution of the command. This blocking thing is not happening in case of the pipeline scenario. Any help is appreciated. Thanks.

答案1

得分: 1

根据这个问题cluster client doesn't retry on pipeline read timeouts,重试策略不适用于管道操作。

这样设计的原因是我们不应该尝试重试管道中的一半命令,因为用户可能依赖于所有命令一起执行。

英文:

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.

huangapple
  • 本文由 发表于 2022年9月29日 22:31:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/73897297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定