-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[#3612] Generating unique command cache key #3765
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
base: master
Are you sure you want to change the base?
[#3612] Generating unique command cache key #3765
Conversation
Hi @ShubhamKaudewar, thank you for your contribution! We will review your changes soon. |
@ShubhamKaudewar, you have failures in test_connection.py tests. Also please check linter errors. |
…ew redis_args field
@petyaslavova 3 test case was failing in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a client-side caching issue where different Redis command arguments were generating the same cache key, causing incorrect cached values to be returned. The fix adds a redis_args
field to the CacheKey
class to ensure unique cache keys for commands with different arguments.
- Adds
redis_args
field toCacheKey
class with default empty tuple - Updates cache key creation to include full command arguments
- Updates all test cases to include the new
redis_args
parameter
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
redis/cache.py | Adds redis_args field to CacheKey dataclass |
redis/connection.py | Updates cache key creation to include command arguments and fixes cachability check |
tests/test_connection.py | Updates test cases to include redis_args parameter and fixes error message regex |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
redis/connection.py
Outdated
@@ -1214,7 +1214,7 @@ def send_command(self, *args, **kwargs): | |||
with self._cache_lock: | |||
# Command is write command or not allowed | |||
# to be cached. | |||
if not self._cache.is_cachable(CacheKey(command=args[0], redis_keys=())): | |||
if not self._cache.is_cachable(CacheKey(command=args[0], redis_keys=(), redis_args=())): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Creating a CacheKey with empty tuples just for the cachability check is inefficient. Consider adding a separate method to check if a command is cachable without creating a full CacheKey object.
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
Pull Request check-list
Please make sure to review and check all of these items:
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
PR tries to solve the client-side-caching not updating local cache key for various different args fields. While creating CacheKey model instance's present state only considering command key and key names tuple. Which omitting different field names should have different cache key for HGET.
By maintaining Model field of redis_args for CacheKey class will resolve the issue of having non-uniqueness of key generation.
How to reproduce issue?
Example-1:
mentioned in this issue #3612
Example-2
Conclusion
I was not able to run whole test folder but I have ran
test_encoding
,test_cache
which looks essential for change PR proposing. Feel free to update me by adding comments, I am new to contribution would like to incorporate changes