...

Source file src/github.com/go-redis/redis/internal/internal.go

Documentation: github.com/go-redis/redis/internal

     1  package internal
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  // Retry backoff with jitter sleep to prevent overloaded conditions during intervals
     9  // https://www.awsarchitectureblog.com/2015/03/backoff.html
    10  func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration {
    11  	if retry < 0 {
    12  		retry = 0
    13  	}
    14  
    15  	backoff := minBackoff << uint(retry)
    16  	if backoff > maxBackoff || backoff < minBackoff {
    17  		backoff = maxBackoff
    18  	}
    19  
    20  	if backoff == 0 {
    21  		return 0
    22  	}
    23  	return time.Duration(rand.Int63n(int64(backoff)))
    24  }
    25  

View as plain text