Repository navigation
feat(caching): give RedisCache a pub/sub and lease surface and drop raw client reaches - #42984
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
…aw client reaches Add async_publish and async_subscribe to the Python RedisCache, returning a RedisSubscription that yields RedisMessage values and skips redis-py's subscribe acks, plus connection_pool_status for the debug endpoint. Cluster clients raise NotImplementedError, matching the existing skip behaviour. Move the config sync and auth cache invalidation modules onto that surface and rewrite the MCP refresh lock onto async_register_script, so no proxy code reaches into init_async_client or redis_client any more. This defines the surface a native RedisCache has to match. On the Rust side add the PubSubCache and MessageStream capability traits and implement them in cache-redis with a dedicated subscription connection driven by a reader thread, tested against an in-process RESP server over a real socket.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
| channel: received.get_channel_name().to_owned(), | ||
| payload: received.get_payload_bytes().to_vec(), | ||
| }; | ||
| if sender.blocking_send(Ok(message)).is_err() { |
There was a problem hiding this comment.
| deadline: Final = None if timeout is None else clock() + timeout | ||
| while True: | ||
| remaining = _PUBSUB_WAIT_SLICE_SECONDS if deadline is None else max(deadline - clock(), 0.0) | ||
| frame: object = await self.pubsub.get_message(timeout=remaining) |
There was a problem hiding this comment.
| server = fakeredis.TcpFakeServer(("127.0.0.1", 0), server_type="redis") | ||
| worker = threading.Thread(target=server.serve_forever, daemon=True) | ||
| worker.start() |
There was a problem hiding this comment.
Tests make real network calls This fixture starts a TCP Redis server for tests under
tests/test_litellm/, where the repository requires mock-only tests and forbids real network calls. The new lock-test fixture also starts redis-server and connects over localhost TCP. This repository requirement must be satisfied before merging.
Rule Used: What: prevent any tests from being added here that make real network calls - only mock tests can be added to this folder. Exception: tests/e2e folder, this folder can contain network calls. Why: ensure it runs correctly on github ci/cd + for all d... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| async def async_subscribe(self, *channels: str) -> RedisSubscription: | ||
| pubsub: Final = self._standalone_async_client().pubsub() | ||
| await pubsub.subscribe(*channels) | ||
| return RedisSubscription(pubsub) |
There was a problem hiding this comment.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a proxy operator running several workers against one Redis gets cross-worker coordination, but each feature wires the redis client differently
After: the same deployment gets the same coordination through one RedisCache surface, with a matching Rust backend
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Type
🆕 New Feature
🧹 Refactoring
Screenshots / Proof of Fix
Caveats (if any)
Final Attestation