-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Adding support for CAS/CAD commands. #3837
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?
Conversation
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 pull request adds support for two new Redis 8.4 commands (DELEX and DIGEST) and extends the SET command with new conditional options (IFEQ, IFNE, IFDEQ, IFDNE). The implementation includes both synchronous and asynchronous variants along with comprehensive test coverage.
Key Changes:
- Added
delex()method for conditional key deletion based on value or digest matching - Added
digest()method to compute XXH3 hash digests of string values - Extended
set()method with four new conditional parameters for atomic compare-and-set operations - Introduced
at_most_one_value_set()helper function to simplify mutual exclusivity validation - Added
DIGESTcommand to cluster read-only commands list
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| redis/commands/helpers.py | Adds at_most_one_value_set() helper function for mutual exclusivity checks |
| redis/commands/core.py | Implements delex() and digest() methods, extends set() with new conditionals, refactors mutual exclusivity checks |
| redis/commands/cluster.py | Adds DIGEST to read-only commands list for cluster support |
| tests/test_commands.py | Comprehensive tests for delex(), digest(), and extended set() functionality |
| tests/test_asyncio/test_commands.py | Async variants of all new tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adding support for new CAS/CAD commands that are part of Redis 8.4 release.
Adding new command: DIGEST
Command definition:
DIGEST keyGet the hash digest of the value stored in key, as a hex string.
Extending SET command to enable the following arguments:
Command definition:
SET key value [NX | XX | IFEQ match-value | IFNE match-value | IFDEQ match-digest | IFDNEmatch-digest] [GET] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]IFEQ match-value - Set the key’s value and expiration only if its current value is equal to match-value. If key doesn’t exist - it won’t be created.
IFNE match-value - Set the key’s value and expiration only if its current value is not equal to match-value. If key doesn’t exist - it will be created.
IFDEQ match-digest - Set the key’s value and expiration only if the digest of its current value is equal to match-digest. If key doesn’t exist - it won’t be created.
IFDNE match-digest - Set the key’s value and expiration only if the digest of its current value is not equal to match-digest. If key doesn’t exist - it will be created.
Adding new command DELEX
Command definition:
DELEX key [IFEQ match-value | IFNE match-value | IFDEQ match-digest | IFDNE match-digest]Conditionally removes the specified key. A key is ignored if it does not exist.
IFEQ match-value - Delete the key only if its value is equal to match-value
IFNE match-value - Delete the key only if its value is not equal to match-value
IFDEQ match-digest - Delete the key only if the digest of its value is equal to match-digest
IFDNE match-digest - Delete the key only if the digest of its value is not equal to match-digest