Pass zrank/zrevrank keys so they are cacheable (fixes ValueError under CSC) - #4249
Open
uttam12331 wants to merge 1 commit into
Open
Pass zrank/zrevrank keys so they are cacheable (fixes ValueError under CSC)#4249uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
ZRANK and ZREVRANK are in the client-side cache allow list, but neither set
options["keys"], so building the cache key raised
ValueError("Cannot create cache key.") whenever caching was enabled.
Set options["keys"] = [name] for both, matching the range commands, and add
a regression test that caches zrank/zrevrank and checks invalidation.
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.
Summary
ZRANKandZREVRANKare in the client-side cache allow list (redis/cache.py), but neither setsoptions["keys"]. When client-side caching is enabled, building the cache key raises:(from
redis/connection.py,if kwargs.get("keys") is None: raise ValueError("Cannot create cache key.")), so these two commands can't be used with caching at all.This was pointed out by @petyaslavova in #4244:
Fix
Set
options["keys"] = [name]in bothzrankandzrevrank, matching the range commands:options = {"withscore": withscore, "score_cast_func": score_cast_func} + options["keys"] = [name] return self.execute_command(*pieces, **options)Tests
Added
test_zrank_zrevrank_are_cacheable(intests/test_cache.py), which cacheszrank/zrevrank(noValueError), asserts the entries are stored underredis_keys=("myzset",), and that mutating the sorted set from a second client invalidates them.Note
Low Risk
Small, pattern-aligned change to command options plus cache tests; no auth, security, or data-model impact.
Overview
Fixes client-side caching for
ZRANKandZREVRANK. Those commands were on the cache allow list but did not passoptions["keys"], soexecute_commandraisedValueError: Cannot create cache key.whenever CSC was enabled.Both
zrankandzrevranknow setoptions["keys"] = [name], consistent with other sorted-set read helpers (e.g.zrange). Cache entries are keyed on the sorted-set name and invalidate when that key changes.A new cache test confirms ranks can be cached without error, entries appear under
redis_keys=("myzset",), and azaddfrom a second client refreshes stale ranks.Reviewed by Cursor Bugbot for commit 4d16982. Bugbot is set up for automated code reviews on this repo. Configure here.