0.1.0-fixes
All checks were successful
deploy / deploy (push) Successful in 1m11s

This commit is contained in:
2023-12-22 12:09:03 +03:00
parent 5c6a680832
commit e22d5468ab
12 changed files with 340 additions and 171 deletions

View File

@@ -1,4 +1,3 @@
import asyncio
import json
import redis.asyncio as aredis
@@ -49,19 +48,19 @@ class RedisCache:
return
await self._client.publish(channel, data)
async def listen(self, channel):
async def listen(self, pattern):
if self._client:
pubsub = self._client.pubsub()
await pubsub.subscribe(channel)
await pubsub.psubscribe(pattern)
while True:
message = await pubsub.get_message()
if message and isinstance(message["data"], (str, bytes, bytearray)):
print(f"[services.rediscache] msg: {message}")
try:
yield json.loads(message["data"])
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}")
await asyncio.sleep(0.1)
yield json.loads(message["data"]), message.get("channel")
except Exception as e:
print(f"[servoces.rediscache] Error: {e}")
redis = RedisCache()