-
Notifications
You must be signed in to change notification settings - Fork 653
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
Set Command with IFEQ Support #1324
base: unstable
Are you sure you want to change the base?
Set Command with IFEQ Support #1324
Conversation
c2dbcba
to
14c5fd9
Compare
14c5fd9
to
6c216c1
Compare
Signed-off-by: Sarthak Aggarwal <[email protected]>
6c216c1
to
ed26e4b
Compare
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.
Would be nice to think through the behavior with other flags/parameters of SET command https://valkey.io/commands/set/
NX -- Only set the key if it does not already exist
- I think NX
should take higher precedence.
XX -- Only set the key if it already exists
- This becomes redundant to use I believe with CAS.
GET -- Return the old string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
- I think we need to support this parameter in some form. The scenario which comes to my mind is when CAS fails and a user doesn't need to send a GET command again to find out the value stored in the engine. However, we need to think about how to differentiate between success scenario vs failure scenario.
Also, we need to document them.
@@ -582,6 +582,19 @@ if {[string match {*jemalloc*} [s mem_allocator]]} { | |||
set err1 | |||
} {*WRONGTYPE*} | |||
|
|||
test "SET with IFEQ conditional" { |
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.
Could you also add test case for interaction with other parameters?
/* Handle the IFEQ conditional check */ | ||
if ((flags & OBJ_SET_IFEQ) && found) { | ||
robj *current_value = lookupKeyRead(c->db, key); | ||
if (current_value == NULL || compareStringObjects(current_value, comparison) != 0) { |
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.
What happens if the value currently stored isn't a STRING data type? I also think we should return an error message in that case.
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.
Add a test case as well.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #1324 +/- ##
=========================================
Coverage 70.73% 70.74%
=========================================
Files 115 115
Lines 63160 63192 +32
=========================================
+ Hits 44678 44705 +27
- Misses 18482 18487 +5
|
This PR allows the Valkey users to perform conditional updates where the SET command is completed if the given comparison-value matches the key’s current value.
Behavior with this PR
If the values match, the SET completes as expected. If they do not match, the command returns a (nil).
Addresses: #1215