File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1212
1313import hglib
1414import structlog
15+ from redis .backoff import NoBackoff
1516from 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
1728log = 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 ()
You can’t perform that action at this time.
0 commit comments