Skip to content

fix(redis): report each key's expiry to the monitoring routes - #94

Merged
allen0099 merged 1 commit into
masterfrom
fix/redis-cache-data-ttl
Sep 25, 2026
Merged

allen0099 merged 1 commit into
masterfrom
fix/redis-cache-data-ttl

Conversation

@allen0099

Copy link
Copy Markdown
Owner

Closes #74.

Change

AsyncRedisCacheBackend.get_cache_data() returned (entry, None) for every key. As a result, /cached-hits and /cached-records showed Redis entries as never expiring (ttl_remaining: null).

It now adds a PTTL next to each GET in the same pipeline, so it is still one round-trip per call. It converts the reply to the absolute time.time() expiry the memory backend reports:

  • -1 (no TTL) maps to None.
  • -2 (the key expired or was deleted between SCAN and the fetch) is skipped.

The Redis notes in docs/CACHE_FLOW.md and docs/HTTP_CACHING.md no longer say the TTL is unavailable. [Unreleased] has a Fixed entry.

Tests

  • New test_redis_get_cache_data_reports_absolute_expiry: a key set with ttl=60 reports an expiry within [before+59, after+60], and a key without a ttl reports None. It fails on the old code.
  • New test_redis_get_cache_data_skips_keys_gone_after_scan: guards the -2 path. It also passes on the old code, where the missing value was already dropped, so it is there to stop a regression.
  • Full suite against the throwaway Redis (6380) and Memcached (11212) test servers: 691 passed, 1 skipped, coverage 100%. ruff and mypy --strict are clean.

AsyncRedisCacheBackend.get_cache_data() returned (entry, None) for every
key, so /cached-hits and /cached-records showed Redis entries as never
expiring. It now queues PTTL next to each GET in the same pipeline and
converts it to the absolute time.time() expiry the memory backend reports.
PTTL -1 maps to None, and a key that vanished between SCAN and the fetch
(PTTL -2) is skipped.

Closes #74
@allen0099
allen0099 merged commit 7279983 into master Sep 25, 2026
10 checks passed
@allen0099
allen0099 deleted the fix/redis-cache-data-ttl branch September 25, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis backend reports no TTL to the monitoring routes

1 participant