mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Added backoff retry
This commit is contained in:
committed by
Vladimir Mihailenco
parent
368f0ea0ba
commit
406e882c43
24
options.go
24
options.go
@ -34,6 +34,10 @@ type Options struct {
|
||||
// Default is to not retry failed commands.
|
||||
MaxRetries int
|
||||
|
||||
// Retry using exponential backoff wait algorithm between each retry
|
||||
// Default is 512 milliseconds; set to -1 to disable any backoff sleep
|
||||
MaxRetryBackoff time.Duration
|
||||
|
||||
// Dial timeout for establishing new connections.
|
||||
// Default is 5 seconds.
|
||||
DialTimeout time.Duration
|
||||
@ -89,15 +93,17 @@ func (opt *Options) init() {
|
||||
if opt.DialTimeout == 0 {
|
||||
opt.DialTimeout = 5 * time.Second
|
||||
}
|
||||
if opt.ReadTimeout == 0 {
|
||||
opt.ReadTimeout = 3 * time.Second
|
||||
} else if opt.ReadTimeout == -1 {
|
||||
switch opt.ReadTimeout {
|
||||
case -1:
|
||||
opt.ReadTimeout = 0
|
||||
case 0:
|
||||
opt.ReadTimeout = 3 * time.Second
|
||||
}
|
||||
if opt.WriteTimeout == 0 {
|
||||
opt.WriteTimeout = opt.ReadTimeout
|
||||
} else if opt.WriteTimeout == -1 {
|
||||
switch opt.WriteTimeout {
|
||||
case -1:
|
||||
opt.WriteTimeout = 0
|
||||
case 0:
|
||||
opt.WriteTimeout = opt.ReadTimeout
|
||||
}
|
||||
if opt.PoolTimeout == 0 {
|
||||
opt.PoolTimeout = opt.ReadTimeout + time.Second
|
||||
@ -108,6 +114,12 @@ func (opt *Options) init() {
|
||||
if opt.IdleCheckFrequency == 0 {
|
||||
opt.IdleCheckFrequency = time.Minute
|
||||
}
|
||||
switch opt.MaxRetryBackoff {
|
||||
case -1:
|
||||
opt.MaxRetryBackoff = 0
|
||||
case 0:
|
||||
opt.MaxRetryBackoff = 512 * time.Millisecond
|
||||
}
|
||||
}
|
||||
|
||||
// ParseURL parses a redis URL into options that can be used to connect to redis
|
||||
|
Reference in New Issue
Block a user