我正在尝试使用maxRetries选项的go客户端.
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)
}
}以上注释的代码没有管道。在这种情况下,当循环被执行时,如果redis关闭,那么我会看到命令的执行一直阻塞到15秒(由于重试),然后执行下一个命令。一旦出现redis,循环就会继续,成功地执行命令。在管道场景中,这种阻塞事件不会发生。任何帮助都是非常感谢的。谢谢。
发布于 2022-09-30 11:40:27
根据此问题集群客户端不重试管道读取超时,重试策略不适用于管道。
其动机是我们不应该尝试重试一半的管道,因为用户依赖于管道中的所有命令一起执行一次。
https://stackoverflow.com/questions/73897297
复制相似问题