1
0
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:
Jonathan Chan
2017-05-25 01:08:44 -04:00
committed by Vladimir Mihailenco
parent 368f0ea0ba
commit 406e882c43
7 changed files with 110 additions and 8 deletions

View File

@ -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