redis-service-fix

This commit is contained in:
Untone 2024-01-24 15:36:34 +03:00
parent 06699a000a
commit 8c33955d5c

View File

@ -1,6 +1,10 @@
import redis.asyncio as aredis import redis.asyncio as aredis
from settings import REDIS_URL from settings import REDIS_URL
import logging
logger = logging.getLogger("[services.redis] ")
logger.setLevel(logging.DEBUG)
class RedisCache: class RedisCache:
@ -19,12 +23,13 @@ class RedisCache:
async def execute(self, command, *args, **kwargs): async def execute(self, command, *args, **kwargs):
if self._client: if self._client:
try: try:
print("[redis] " + command + " " + " ".join(args)) logger.debug(f"{command} {args} {kwargs}")
r = await self._client.execute_command(command, *args, **kwargs) r = await self._client.execute_command(command, *args, **kwargs)
logger.debug(type(r))
logger.debug(r)
return r return r
except Exception as e: except Exception as e:
print(f"[redis] error: {e}") logger.error(e)
return None
async def subscribe(self, *channels): async def subscribe(self, *channels):
if self._client: if self._client:
@ -46,7 +51,6 @@ class RedisCache:
return return
await self._client.publish(channel, data) await self._client.publish(channel, data)
redis = RedisCache() redis = RedisCache()
__all__ = ["redis"] __all__ = ["redis"]