mirror of
https://github.com/redis/go-redis.git
synced 2025-08-07 12:42:55 +03:00
Close connections to unused nodes
This commit is contained in:
@@ -5,19 +5,20 @@ import (
|
||||
"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 {
|
||||
func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration {
|
||||
if retry < 0 {
|
||||
retry = 0
|
||||
}
|
||||
|
||||
backoff := retryBackoff << uint(retry)
|
||||
if backoff > maxRetryBackoff {
|
||||
backoff = maxRetryBackoff
|
||||
backoff := minBackoff << uint(retry)
|
||||
if backoff > maxBackoff || backoff < minBackoff {
|
||||
backoff = maxBackoff
|
||||
}
|
||||
|
||||
if backoff == 0 {
|
||||
return 0
|
||||
}
|
||||
return time.Duration(rand.Int63n(int64(backoff)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user