fixed connection error handling

This commit is contained in:
Brian Bjarke Jensen
2025-09-14 19:52:39 +02:00
parent 969c2c8170
commit 524bd0f06b
+10 -7
View File
@@ -62,12 +62,15 @@ class RedisAdapter(
# Prepare arguments # Prepare arguments
uri = str(os.getenv(self.uri_env_var_name)) uri = str(os.getenv(self.uri_env_var_name))
# Connect client # Connect client
client = redis.Redis.from_url( try:
url=uri, client = redis.Redis.from_url(
socket_connect_timeout=10, url=uri,
) socket_connect_timeout=10,
if not client.ping(): )
raise ConnectionError(f"Could not connect to Redis at {uri}") 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 # Persist client
self._client = client self._client = client
@@ -128,7 +131,7 @@ class RedisAdapter(
self._client.json().delete(key) self._client.json().delete(key)
self.logger.debug(f"Deleted {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.""" """List keys in Redis matching a pattern."""
# Check input # Check input
if not isinstance(pattern, str) or len(pattern) == 0: if not isinstance(pattern, str) or len(pattern) == 0: