25 lines
610 B
Python
25 lines
610 B
Python
import json
|
|
import asyncio
|
|
from app.core.redis import get_redis
|
|
|
|
class RedisManager:
|
|
def __init__(self):
|
|
self.redis = None
|
|
|
|
async def connect(self):
|
|
self.redis = await get_redis()
|
|
|
|
async def publish(self, channel: str, message: str):
|
|
if not self.redis:
|
|
await self.connect()
|
|
await self.redis.publish(channel, message)
|
|
|
|
async def subscribe(self, channel: str):
|
|
if not self.redis:
|
|
await self.connect()
|
|
pubsub = self.redis.pubsub()
|
|
await pubsub.subscribe(channel)
|
|
return pubsub
|
|
|
|
redis_manager = RedisManager()
|