Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

quality: Return success callback for cache as a bool

Clémence Lesnéab31f4a26337
diff --git a/persistence/icache.py b/persistence/icache.py
index e55ad7f..07d3118 100644
--- a/persistence/icache.py
+++ b/persistence/icache.py
@@ -8,5 +8,5 @@ class ICache(ABC):
pass
@abstractmethod
- async def aset(self, key: str, value: Union[str, bytes, None]) -> None:
+ async def aset(self, key: str, value: Union[str, bytes, None]) -> bool:
pass
diff --git a/persistence/memory.py b/persistence/memory.py
index ea54a18..32d679c 100644
--- a/persistence/memory.py
+++ b/persistence/memory.py
@@ -23,7 +23,7 @@ class MemoryCache(ICache):
"""
return self._cache.get(key, None)
- async def aset(self, key: str, value: Union[str, bytes, None]) -> None:
+ async def aset(self, key: str, value: Union[str, bytes, None]) -> bool:
"""
Set a value in the cache.
@@ -32,3 +32,4 @@ class MemoryCache(ICache):
if len(self._cache) >= self._config.max_size:
self._cache = {}
self._cache[key] = value.encode() if isinstance(value, str) else value
+ return True
diff --git a/persistence/redis.py b/persistence/redis.py
index ad334cd..9d04c2e 100644
--- a/persistence/redis.py
+++ b/persistence/redis.py
@@ -33,7 +33,7 @@ class RedisCache(ICache):
res = await db.get(key)
return res
- async def aset(self, key: str, value: Union[str, bytes, None]) -> None:
+ async def aset(self, key: str, value: Union[str, bytes, None]) -> bool:
"""
Set a value in the cache.
@@ -41,8 +41,10 @@ class RedisCache(ICache):
Catch errors for a maximum of 3 times, then raise the error.
"""
+ # TODO: Catch errors
async with self._use_db() as db:
await db.set(key, value if value else "")
+ return True
@asynccontextmanager
async def _use_db(self) -> AsyncGenerator[Redis, None]: