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
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: