fixed connection error handling
This commit is contained in:
@@ -62,12 +62,15 @@ class RedisAdapter(
|
||||
# Prepare arguments
|
||||
uri = str(os.getenv(self.uri_env_var_name))
|
||||
# Connect client
|
||||
client = redis.Redis.from_url(
|
||||
url=uri,
|
||||
socket_connect_timeout=10,
|
||||
)
|
||||
if not client.ping():
|
||||
raise ConnectionError(f"Could not connect to Redis at {uri}")
|
||||
try:
|
||||
client = redis.Redis.from_url(
|
||||
url=uri,
|
||||
socket_connect_timeout=10,
|
||||
)
|
||||
if not client.ping():
|
||||
raise ConnectionError(f"Could not connect to Redis at {uri}")
|
||||
except (redis.ConnectionError, redis.TimeoutError) as exc:
|
||||
raise ConnectionError(f"Could not connect to Redis at {uri}") from exc
|
||||
# Persist client
|
||||
self._client = client
|
||||
|
||||
@@ -128,7 +131,7 @@ class RedisAdapter(
|
||||
self._client.json().delete(key)
|
||||
self.logger.debug(f"Deleted {key}")
|
||||
|
||||
async def _list_keys(self, pattern: str) -> list[str]:
|
||||
def _list_keys(self, pattern: str) -> list[str]:
|
||||
"""List keys in Redis matching a pattern."""
|
||||
# Check input
|
||||
if not isinstance(pattern, str) or len(pattern) == 0:
|
||||
|
||||
Reference in New Issue
Block a user