fix: hash method parameter naming and key handling#812
Conversation
b2b95a8 to
57386d6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #812 +/- ##
========================================
- Coverage 38.3% 38.2% -0.0%
========================================
Files 48 48
Lines 3727 3776 +49
Branches 301 301
========================================
+ Hits 1425 1440 +15
- Misses 2001 2035 +34
Partials 301 301
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Changed hash method parameters to align with Redis/Valkey terminology: - Renamed 'name' → 'key' (the Redis key for the hash) - Renamed 'key' → 'field' (the field within the hash) - Changed type from 'str' to 'KeyT' for consistency with other methods - Added 'version' parameter support to hlen() and hkeys() Fixed make_key() application: - make_key() now only applied to hash key (first parameter) - Fields are no longer transformed with make_key() - This fixes the namespacing issue where fields were incorrectly prefixed - hkeys() now returns plain field names without reverse_key processing Added comprehensive test for version support across all hash methods. This improves API clarity and consistency with Redis/Valkey documentation where 'key' refers to the Redis key (name of the hash structure) and 'field' refers to a field within that hash. Changed methods: - hset(key, field, value, ...) - hdel(key, field, ...) - hlen(key, ...) - hkeys(key, ...) - hexists(key, field, ...) All hash-related tests pass with the new implementation. Co-authored-by: 2ykwang <yk2ykwang@gmail.com>
57386d6 to
d95e930
Compare
Moved all hash operation tests from test_backend.py to a new dedicated test_backend_hash.py file for better organization and maintainability. Tests moved: - test_hset - test_hdel - test_hlen - test_hkeys - test_hexists - test_hash_version_support - test_hash_key_structure_in_redis All 84 hash tests (7 tests × 12 cache configurations) pass.
There was a problem hiding this comment.
Please don't refactor things while you're fixing as it makes it harder to tell if you just made the tests work for broken code.
terencehonles
left a comment
There was a problem hiding this comment.
The typing is not correct because it is too strict (enforces Redis' types), but that is out of scope for this PR.
d1128a5 to
6e95c04
Compare
6e95c04 to
858aa57
Compare
| return int( | ||
| client.hset( | ||
| nkey, | ||
| key=field, # type: ignore[arg-type] |
There was a problem hiding this comment.
There are is an issue with the Redis type hints and I will create a PR to fix those (it is a bigger change), but for now I just silenced these errors.
Changed hash method parameters to align with Redis/Valkey terminology:
NOTE: This is the naming convention of the Redis and Valkey docs, and unfortunately redis-py code has the naming differently, but I would go with the former, which also fits more with Django's naming.
Fixed make_key() application including version kwarg:
See also #765, and I tried to credit 2ykwang in the commits, hopefully that works. Without the naming changes above their PR was a bit confusing though, so I packed this into one.
Let me know if I should change something here.
fixes: #794