"""Redis client and pub/sub utilities for inter-service communication. All services that need Redis import from here. """ from __future__ import annotations import redis.asyncio as aioredis from shared.config import settings redis_client: aioredis.Redis = aioredis.from_url( settings.REDIS_URL, decode_responses=True, ) # ── Channel naming conventions ──────────────────────────────────────── # See /memories/repo/microservices-architecture.md for full list. def ws_out_channel(user_id: str) -> str: """Frames to forward to Electron via WS Gateway.""" return f"ws:out:{user_id}" def chat_request_channel(user_id: str) -> str: """Chat requests (home + floating) from WS Gateway → Chat Service.""" return f"chat:request:{user_id}" def batch_request_channel(user_id: str) -> str: """Batch requests (journey + triggers) from WS Gateway → Batch Agent.""" return f"batch:request:{user_id}" def tool_result_key(call_id: str) -> str: """Tool result list: LPUSH by WS Gateway, BRPOP by Chat/Batch.""" return f"tool:result:{call_id}" def device_key(user_id: str) -> str: """Device registry hash.""" return f"ws:devices:{user_id}" def tier_changed_channel(user_id: str) -> str: """Billing tier change notifications.""" return f"tier:changed:{user_id}" def journey_session_key(user_id: str) -> str: """Journey builder session (String + TTL 1800s).""" return f"journey:{user_id}"