fix(redis): report each key's expiry to the monitoring routes - #94
Merged
Merged
Conversation
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #74.
Change
AsyncRedisCacheBackend.get_cache_data()returned(entry, None)for every key. As a result,/cached-hitsand/cached-recordsshowed Redis entries as never expiring (ttl_remaining: null).It now adds a
PTTLnext to eachGETin the same pipeline, so it is still one round-trip per call. It converts the reply to the absolutetime.time()expiry the memory backend reports:-1(no TTL) maps toNone.-2(the key expired or was deleted betweenSCANand the fetch) is skipped.The Redis notes in
docs/CACHE_FLOW.mdanddocs/HTTP_CACHING.mdno longer say the TTL is unavailable.[Unreleased]has a Fixed entry.Tests
test_redis_get_cache_data_reports_absolute_expiry: a key set withttl=60reports an expiry within[before+59, after+60], and a key without a ttl reportsNone. It fails on the old code.test_redis_get_cache_data_skips_keys_gone_after_scan: guards the-2path. It also passes on the old code, where the missing value was already dropped, so it is there to stop a regression.ruffandmypy --strictare clean.