MCPcopy
hub / github.com/redis/redis-py / ExponentialWithJitterBackoff

Class ExponentialWithJitterBackoff

redis/backoff.py:158–179  ·  view source on GitHub ↗

Exponential backoff upon failure, with jitter

Source from the content-addressed store, hash-verified

156
157
158class ExponentialWithJitterBackoff(AbstractBackoff):
159 """Exponential backoff upon failure, with jitter"""
160
161 def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None:
162 """
163 `cap`: maximum backoff time in seconds
164 `base`: base backoff time in seconds
165 """
166 self._cap = cap
167 self._base = base
168
169 def __hash__(self) -> int:
170 return hash((self._base, self._cap))
171
172 def __eq__(self, other) -> bool:
173 if not isinstance(other, ExponentialWithJitterBackoff):
174 return NotImplemented
175
176 return self._base == other._base and self._cap == other._cap
177
178 def compute(self, failures: int) -> float:
179 return min(self._cap, random.random() * self._base * 2**failures)
180
181
182def default_backoff():

Callers 14

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
MultiDbConfigClass · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls