Skip to content

Commit 9c1f6d6

Browse files
committed
For Redis add retry policy
1 parent 866278c commit 9c1f6d6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

libmozevent/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212

1313
import hglib
1414
import structlog
15+
from redis.backoff import NoBackoff
1516
from redis import asyncio as aioredis
17+
from redis.asyncio.retry import Retry
18+
from redis.exceptions import (
19+
ConnectionError,
20+
ExecAbortError,
21+
PubSubError,
22+
RedisError,
23+
ResponseError,
24+
TimeoutError,
25+
WatchError,
26+
)
1627

1728
log = structlog.get_logger(__name__)
1829

@@ -175,16 +186,31 @@ class AsyncRedis(object):
175186
@staticmethod
176187
async def connect():
177188
if AsyncRedis.redis.get(None) is None:
189+
retry_on_error = [
190+
ConnectionError,
191+
ExecAbortError,
192+
PubSubError,
193+
RedisError,
194+
ResponseError,
195+
TimeoutError,
196+
WatchError,
197+
]
198+
199+
retries = 5
178200
AsyncRedis.redis.set(
179201
await aioredis.from_url(
180202
os.environ["REDIS_TLS_URL"],
181203
decode_responses=False,
182204
ssl_cert_reqs=None,
205+
retry_on_error=retry_on_error,
206+
retry=Retry(NoBackoff(), retries),
183207
)
184208
if os.getenv("REDIS_TLS_URL", None) is not None
185209
else await aioredis.from_url(
186210
os.environ["REDIS_URL"],
187211
decode_responses=False,
212+
retry_on_error=retry_on_error,
213+
retry=Retry(NoBackoff(), retries),
188214
)
189215
)
190216
return AsyncRedis.redis.get()

0 commit comments

Comments
 (0)