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.