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 cachedConnectionPoolfrom_get_or_build_db12_pool(), so the actual TCP sockets are pooled and reused rather than opened and torn down every call.Yields
Nonewhen ctx or itsredishandle is unavailable, so callers canasync with db12_client(ctx) as db12: if db12 is None: returnwithout a separate existence check.- Parameters:
ctx (
ToolContext|None) β The activeToolContextsupplying the main Redis client whose connection kwargs seed the DB12 pool.Nonedegrades to a no-op client (Noneyielded).