tools.parallax_db12 module

Shared DB12 Redis client for the Parallax family of tools. πŸ’€πŸ”₯

parallax_tool.py, xray_tool.py, and parallax_telemetry.py all used to spin up a brand-new ConnectionPool (and matching redis.asyncio.Redis client) EVERY call just to reach logical database 12 – only ever calling aclose() on the client and never pool.disconnect(), so the pools (and their underlying sockets) leaked. This module caches ONE ConnectionPool per source pool (keyed by identity, since different callers may carry different underlying pools across worker processes) and hands out short-lived clients bound to it via an async contextmanager. Sockets are reused across calls instead of torn down and rebuilt every time. πŸŒ€

tools.parallax_db12.db12_client(ctx)

Yield a DB12-bound Redis client backed by the shared cached pool.

Replaces the repeated β€œspin up a fresh ConnectionPool + client, use it once, aclose() it” pattern that used to live in six-plus places across the Parallax tool family. The client itself is still created per-call (cheap – it’s just a thin wrapper), but it shares the long-lived cached ConnectionPool from _get_or_build_db12_pool(), so the actual TCP sockets are pooled and reused rather than opened and torn down every call.

Yields None when ctx or its redis handle is unavailable, so callers can async with db12_client(ctx) as db12: if db12 is None: return without a separate existence check.

Parameters:

ctx (ToolContext | None) – The active ToolContext supplying the main Redis client whose connection kwargs seed the DB12 pool. None degrades to a no-op client (None yielded).