Skip to content

Conversation

ShubhamKaudewar
Copy link
Contributor

@ShubhamKaudewar ShubhamKaudewar commented Sep 6, 2025

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

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

import redis
from redis.cache import CacheConfig

url = 'xxx'
name = 'abcde'

r = redis.from_url(url, protocol=3, cache_config=CacheConfig())
r1 = redis.from_url(url)
r1.hset(name, key="field3", value="ccc")
r1.hset(name, key="field4", value="ddd")
r1.hset(name, key="field5", value="eee")

print(r.hget(name, "field3")) # print b'ccc' -> After fix print b'ccc'
print(r.hget(name, 'field4')) # print b'ccc' -> After fix print b'ddd'
print(r.hget(name, 'field5')) # print b'ccc' -> After fix print b'eee'
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

@petyaslavova
Copy link
Collaborator

Hi @ShubhamKaudewar, thank you for your contribution! We will review your changes soon.

@petyaslavova
Copy link
Collaborator

@ShubhamKaudewar, you have failures in test_connection.py tests. Also please check linter errors.

@ShubhamKaudewar
Copy link
Contributor Author

@petyaslavova 3 test case was failing in test_connection.py file

  • test_network_connection_failure error message is different for Window OS so made fix for universal check
  • test_unix_socket_connection_failure as name mention Window OS doesn't support Unix so added bypass
  • test_read_response_returns_cached_reply since there is additional redis_args field had to fix the test case for the new need

@petyaslavova petyaslavova requested a review from Copilot September 9, 2025 13:09
Copy link
Contributor

@Copilot Copilot AI left a 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 to CacheKey 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.

@@ -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=())):
Copy link
Preview

Copilot AI Sep 9, 2025

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.

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.

2 participants