mirror of
https://github.com/redis/go-redis.git
synced 2025-07-29 17:41:15 +03:00
Added backoff retry
This commit is contained in:
committed by
Vladimir Mihailenco
parent
368f0ea0ba
commit
406e882c43
23
internal/internal.go
Normal file
23
internal/internal.go
Normal file
@ -0,0 +1,23 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
const retryBackoff = 8 * time.Millisecond
|
||||
|
||||
// Retry backoff with jitter sleep to prevent overloaded conditions during intervals
|
||||
// https://www.awsarchitectureblog.com/2015/03/backoff.html
|
||||
func RetryBackoff(retry int, maxRetryBackoff time.Duration) time.Duration {
|
||||
if retry < 0 {
|
||||
retry = 0
|
||||
}
|
||||
|
||||
backoff := retryBackoff << uint(retry)
|
||||
if backoff > maxRetryBackoff {
|
||||
backoff = maxRetryBackoff
|
||||
}
|
||||
|
||||
return time.Duration(rand.Int63n(int64(backoff)))
|
||||
}
|
Reference in New Issue
Block a user