This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user