Add public repository interfaces and subclassable adapter CRUD API.
Define split JSON and object repository ABCs, promote adapter methods to public CRUD, add example domain repositories, modernize interface stubs, and make the package installable for tests. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
f4280f15c1
commit
e98fd3b90d
@@ -9,8 +9,9 @@ import structlog
|
||||
from python_utils import check_env
|
||||
|
||||
from python_repositories.interfaces import (
|
||||
ContextAwareInterface,
|
||||
ConnectionAwareInterface,
|
||||
ContextAwareInterface,
|
||||
JsonRepositoryInterface,
|
||||
)
|
||||
|
||||
# Handle optional dependencies
|
||||
@@ -20,6 +21,7 @@ if find_spec("redis") is not None:
|
||||
|
||||
|
||||
class RedisAdapter(
|
||||
JsonRepositoryInterface,
|
||||
ContextAwareInterface,
|
||||
ConnectionAwareInterface,
|
||||
):
|
||||
@@ -92,7 +94,7 @@ class RedisAdapter(
|
||||
self.logger.debug(res)
|
||||
return res
|
||||
|
||||
def _set(self, key: str, data: dict) -> None:
|
||||
def set(self, key: str, data: dict) -> None:
|
||||
"""Set a JSON object in Redis."""
|
||||
# Check input
|
||||
if not isinstance(key, str) or len(key) == 0:
|
||||
@@ -106,7 +108,7 @@ class RedisAdapter(
|
||||
self._client.json().set(key, self.path, data)
|
||||
self.logger.debug(f"Set {key} to {data}")
|
||||
|
||||
def _get(self, key: str) -> dict | None:
|
||||
def get(self, key: str) -> dict | None:
|
||||
"""Get a JSON object from Redis."""
|
||||
# Check input
|
||||
if not isinstance(key, str) or len(key) == 0:
|
||||
@@ -122,7 +124,7 @@ class RedisAdapter(
|
||||
self.logger.debug(f"Got {data} from {key}")
|
||||
return data
|
||||
|
||||
def _delete(self, key: str) -> None:
|
||||
def delete(self, key: str) -> None:
|
||||
"""Delete data from Redis."""
|
||||
# Check input
|
||||
if not isinstance(key, str) or len(key) == 0:
|
||||
@@ -134,7 +136,7 @@ class RedisAdapter(
|
||||
self._client.json().delete(key)
|
||||
self.logger.debug(f"Deleted {key}")
|
||||
|
||||
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