added redis adapter #1

Merged
brian merged 13 commits from collect-code-from-other-repos into main 2025-09-14 20:42:51 +02:00
Showing only changes of commit 524bd0f06b - Show all commits
+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: