import json import redis.asyncio as redis class RedisClient: def __init__(self, host: str, port: int, task_channel: str, result_channel: str): self.client = redis.Redis(host=host, port=port, decode_responses=True) self.task_channel = task_channel self.result_channel = result_channel async def subscribe_tasks(self): pubsub = self.client.pubsub() await pubsub.subscribe(self.task_channel) return pubsub async def publish_result(self, result: dict): await self.client.publish(self.result_channel, json.dumps(result))