Enable automatic retry on redis errors (#4595)
* Enable automatic retry on redis errors ExponentialBackoff 3x retry for BusyLoadingError, ConnectionError, and TimeoutError * retry on any redis error * Use default single-retry for any RedisError Using the default Retry means that async and sync clients get the appropriate type of Retry
This commit is contained in:
parent
eae15e3a83
commit
72d7616726
@ -28,8 +28,8 @@ import typer
|
||||
from alembic.util.exc import CommandError
|
||||
from packaging import version
|
||||
from redis import Redis as RedisSync
|
||||
from redis import exceptions
|
||||
from redis.asyncio import Redis
|
||||
from redis.exceptions import RedisError
|
||||
|
||||
from reflex import constants, model
|
||||
from reflex.compiler import templates
|
||||
@ -333,10 +333,11 @@ def get_redis() -> Redis | None:
|
||||
Returns:
|
||||
The asynchronous redis client.
|
||||
"""
|
||||
if isinstance((redis_url_or_options := parse_redis_url()), str):
|
||||
return Redis.from_url(redis_url_or_options)
|
||||
elif isinstance(redis_url_or_options, dict):
|
||||
return Redis(**redis_url_or_options)
|
||||
if (redis_url := parse_redis_url()) is not None:
|
||||
return Redis.from_url(
|
||||
redis_url,
|
||||
retry_on_error=[RedisError],
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
@ -346,14 +347,15 @@ def get_redis_sync() -> RedisSync | None:
|
||||
Returns:
|
||||
The synchronous redis client.
|
||||
"""
|
||||
if isinstance((redis_url_or_options := parse_redis_url()), str):
|
||||
return RedisSync.from_url(redis_url_or_options)
|
||||
elif isinstance(redis_url_or_options, dict):
|
||||
return RedisSync(**redis_url_or_options)
|
||||
if (redis_url := parse_redis_url()) is not None:
|
||||
return RedisSync.from_url(
|
||||
redis_url,
|
||||
retry_on_error=[RedisError],
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def parse_redis_url() -> str | dict | None:
|
||||
def parse_redis_url() -> str | None:
|
||||
"""Parse the REDIS_URL in config if applicable.
|
||||
|
||||
Returns:
|
||||
@ -387,7 +389,7 @@ async def get_redis_status() -> dict[str, bool | None]:
|
||||
redis_client.ping()
|
||||
else:
|
||||
status = None
|
||||
except exceptions.RedisError:
|
||||
except RedisError:
|
||||
status = False
|
||||
|
||||
return {"redis": status}
|
||||
|
Loading…
Reference in New Issue
Block a user