We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 601c1aa commit 91c594bCopy full SHA for 91c594b
redis/backoff.py
@@ -109,6 +109,20 @@ def compute(self, failures: int) -> float:
109
self._previous_backoff = min(self._cap, temp)
110
return self._previous_backoff
111
112
+class ExponentialWithJitterBackoff(AbstractBackoff):
113
+ """Exponential backoff upon failure, with jitter"""
114
+
115
+ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None:
116
+ """
117
+ `cap`: maximum backoff time in seconds
118
+ `base`: base backoff time in seconds
119
120
+ self._cap = cap
121
+ self._base = base
122
123
+ def compute(self, failures: int) -> float:
124
+ return min(self._cap, random.random() * self._base * 2**failures)
125
126
127
def default_backoff():
128
return EqualJitterBackoff()
0 commit comments