Repository navigation
ci(circleci): test Redis behavior against local Redis and print short tracebacks #44062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yuneng-berri
merged 2 commits into
main
from
litellm_cci_redis_tests_and_short_tracebacks
Oct 1, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import asyncio | ||
| import os | ||
| import uuid | ||
| from typing import Final | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from litellm.caching.dual_cache import DualCache | ||
| from litellm.caching.in_memory_cache import InMemoryCache | ||
| from litellm.caching.redis_cache import RedisCache | ||
|
|
||
|
|
||
| def _redis_cache() -> RedisCache: | ||
| return RedisCache(host=os.environ["REDIS_HOST"], port=int(os.environ["REDIS_PORT"])) | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_value_only_in_redis_is_read_once_from_redis_then_from_memory() -> None: | ||
| redis_cache: Final = _redis_cache() | ||
| dual_cache: Final = DualCache(in_memory_cache=InMemoryCache(), redis_cache=redis_cache) | ||
| sync_key: Final = f"redis-only-sync-{uuid.uuid4()}" | ||
| async_key: Final = f"redis-only-async-{uuid.uuid4()}" | ||
| redis_cache.set_cache(sync_key, {"v": "sync"}) | ||
| await redis_cache.async_set_cache(async_key, {"v": "async"}) | ||
|
|
||
| assert dual_cache.get_cache(sync_key) == {"v": "sync"} | ||
| assert await dual_cache.async_get_cache(async_key) == {"v": "async"} | ||
|
|
||
| with ( | ||
| patch.object(redis_cache, "get_cache") as sync_redis_read, | ||
| patch.object(redis_cache, "async_get_cache") as async_redis_read, | ||
| ): | ||
| assert dual_cache.get_cache(sync_key) == {"v": "sync"} | ||
| assert await dual_cache.async_get_cache(async_key) == {"v": "async"} | ||
| sync_redis_read.assert_not_called() | ||
| async_redis_read.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_deleted_key_is_gone_from_both_memory_and_redis() -> None: | ||
| redis_cache: Final = _redis_cache() | ||
| dual_cache: Final = DualCache(in_memory_cache=InMemoryCache(), redis_cache=redis_cache) | ||
| sync_key: Final = f"deleted-sync-{uuid.uuid4()}" | ||
| async_key: Final = f"deleted-async-{uuid.uuid4()}" | ||
| dual_cache.set_cache(sync_key, {"v": "sync"}) | ||
| await dual_cache.async_set_cache(async_key, {"v": "async"}) | ||
|
|
||
| dual_cache.delete_cache(sync_key) | ||
| await dual_cache.async_delete_cache(async_key) | ||
|
|
||
| assert dual_cache.get_cache(sync_key) is None | ||
| assert await dual_cache.async_get_cache(async_key) is None | ||
| assert redis_cache.get_cache(sync_key) is None | ||
| assert await redis_cache.async_get_cache(async_key) is None | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_batch_read_without_an_in_memory_cache_reads_redis() -> None: | ||
| redis_cache: Final = _redis_cache() | ||
| dual_cache: Final = DualCache(in_memory_cache=None, redis_cache=redis_cache) | ||
| key: Final = f"no-memory-{uuid.uuid4()}" | ||
| await redis_cache.async_set_cache(key, {"v": "from-redis"}) | ||
|
|
||
| assert await dual_cache.async_batch_get_cache([key]) == [{"v": "from-redis"}] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_sync_and_async_batch_reads_share_one_redis_without_sync_reads_going_async() -> None: | ||
| redis_cache: Final = _redis_cache() | ||
| dual_cache: Final = DualCache(redis_cache=redis_cache) | ||
| run_id: Final = uuid.uuid4().hex | ||
| sync_keys: Final = [f"sync_{run_id}_{index}" for index in range(5)] | ||
| async_keys: Final = [f"async_{run_id}_{index}" for index in range(5)] | ||
| in_loop_keys: Final = [f"in_loop_{run_id}_{index}" for index in range(3)] | ||
| survivor_key: Final = f"survivor_{run_id}" | ||
| expected: Final = {key: {"key": key} for key in [*sync_keys, *async_keys, *in_loop_keys, survivor_key]} | ||
| await asyncio.gather(*(redis_cache.async_set_cache(key, value, ttl=60) for key, value in expected.items())) | ||
|
|
||
| concurrent_results: Final = await asyncio.gather( | ||
| *(asyncio.to_thread(dual_cache.batch_get_cache, keys=[key]) for key in sync_keys), | ||
| *(dual_cache.async_batch_get_cache(keys=[key]) for key in async_keys), | ||
| ) | ||
| assert list(concurrent_results) == [[expected[key]] for key in [*sync_keys, *async_keys]] | ||
|
|
||
| with patch.object( | ||
| redis_cache, | ||
| "async_batch_get_cache", | ||
| side_effect=AssertionError("sync batch reads must not call async Redis"), | ||
| ): | ||
| in_loop_results: Final = [dual_cache.batch_get_cache(keys=[key]) for key in in_loop_keys] | ||
|
|
||
| assert in_loop_results == [[expected[key]] for key in in_loop_keys] | ||
| assert await dual_cache.async_batch_get_cache(keys=[survivor_key]) == [expected[survivor_key]] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.