Skip to content

fix(redis_cache): apply namespace prefix in delete_cache and async_delete_cache - #26790

Open
elluvium wants to merge 1 commit into
BerriAI:mainfrom
elluvium:fix/redis-namespace-delete
Open

fix(redis_cache): apply namespace prefix in delete_cache and async_delete_cache#26790
elluvium wants to merge 1 commit into
BerriAI:mainfrom
elluvium:fix/redis-namespace-delete

Conversation

@elluvium

@elluvium elluvium commented Apr 29, 2026

Copy link
Copy Markdown

Summary

  • async_delete_cache and delete_cache in litellm/caching/redis_cache.py were not calling check_and_fix_namespace() before issuing the Redis DEL command
  • When a namespace is configured, SET and GET correctly prefix the key (e.g. litellm.caching.caching:cronjob_lock:db_spend_update_job), but DEL targeted the raw key — which does not exist — so it always returned 0
  • This caused PodLockManager to never explicitly release locks; every lock expired by TTL instead, producing a failed to release Redis lock warning on every batch-write cycle for every pod

Changes

  • litellm/caching/redis_cache.py: add key = self.check_and_fix_namespace(key=key) to both async_delete_cache and delete_cache, matching the pattern used in every other cache method
  • tests/test_litellm/caching/test_redis_cache.py: add test_delete_cache_applies_namespace — parametrized over namespace=None and namespace="myns" — asserting the correct key is passed to redis_client.delete in both the async and sync paths

Test plan

  • uv run pytest tests/test_litellm/caching/test_redis_cache.py -v — all 26 tests pass
  • uv run ruff check litellm/caching/redis_cache.py tests/test_litellm/caching/test_redis_cache.py — clean
  • uv run mypy litellm/caching/redis_cache.py --ignore-missing-imports — no issues

When a Redis namespace is configured, SET and GET correctly prefix the
key via check_and_fix_namespace, but DELETE did not — causing the
PodLockManager to always target a non-existent key and never explicitly
release locks (they would expire by TTL instead, with a warning on every cycle).

Adds check_and_fix_namespace to both async_delete_cache and delete_cache,
and covers both paths with a parametrized unit test (namespace=None / "myns").
@CLAassistant

CLAassistant commented Apr 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a namespace prefix bug in RedisCache where delete_cache and async_delete_cache were issuing DEL against raw keys while SET/GET used namespaced keys, causing lock releases to always miss and fall back to TTL expiry. The fix adds the single missing check_and_fix_namespace call to both methods, exactly mirroring the pattern used in every other cache operation.

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with proper test coverage and no regressions.

The change is a one-liner applied to two methods, consistent with the established pattern in all other cache operations. Tests cover both the namespace=None and namespace="myns" cases for both code paths using mocks only. No logic is altered elsewhere.

No files require special attention.

Important Files Changed

Filename Overview
litellm/caching/redis_cache.py Adds check_and_fix_namespace call to async_delete_cache and delete_cache, matching the existing pattern used in every other cache method; also adds type annotation to delete_cache.
tests/test_litellm/caching/test_redis_cache.py Adds test_delete_cache_applies_namespace parametrized over None/"myns" covering both async and sync delete paths with mocks; also removes unused fastapi.testclient.TestClient import.

Reviews (1): Last reviewed commit: "fix(redis_cache): apply namespace in del..." | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing elluvium:fix/redis-namespace-delete (62473fc) with main (3e1479c)

Open in CodSpeed

@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: Auto-merge skipped — the staging branch shin_agent_oss_staging_05_18_2026 has 1279 commit(s) not in your branch. Merging as-is would produce a confusing diff on the staging PR.

Please rebase your branch onto shin_agent_oss_staging_05_18_2026 and push; the agent will re-review automatically.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants