-
Notifications
You must be signed in to change notification settings - Fork 819
Add DELIFEQ command #1975
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
Add DELIFEQ command #1975
Conversation
IMO consider adding a more generic command eg. Also worth considering a more general |
I don't have a better alternative but I agree having |
I think DELIFEQ is a good idea, especially with the motivation that it's useful in the locking algorithm. I agree we can't use DEL IFEQ. It's would be a breaking change. It already means Delete the key named "IFEQ", so we can't do that. @xbasel I also thought about |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #1975 +/- ##
============================================
- Coverage 71.24% 71.24% -0.01%
============================================
Files 122 122
Lines 66030 66043 +13
============================================
+ Hits 47045 47050 +5
- Misses 18985 18993 +8
🚀 New features to boost your workflow:
|
Thanks everyone for taking the time to look at this! 🙏 I'm very open to making changes. Do you want me to update the code to I would love some help with the test failures as well. The codecoverage feels wrong, since the reported untested line is the only line that returns The other test failure, "External Server Tests", I'm a bit unsure of. Would love some pointers on where to start! |
@zuiderkwast |
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.
Don't change to DELIF yet. I guess DELIFEQ is more likely to be chosen. We will need to take a core team decision about the command and syntax. Until that's done, there is no hurry to update the details of the PR.
@PingXie @enjoy-binbin @soloestoy We discussed it in the core meeting with the other 3 TSC folks. We were all aligned, will one of you 👍 so we mark this as an approved decision. |
I'm OK with adding a new command, the current command's name is not the best, but I cannot come up with a better name 😅 . |
@LinusU Will you address the comments so we can finish this up and get it merged? |
@zuiderkwast thanks for all the pointers! 🙏 I've:
Please let me know if there is anything else you want me to do! |
d4e0be8
to
76b2fd4
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.
LGTM
✅ Removed test failure looks unrelated?
|
Yeah the CI error is unrelated. Don't worry about it. |
Apparently you need to |
Signed-off-by: Linus Unnebäck <linus@folkdatorn.se>
Sorry, must have missed that the last time 🙈 I've rebased on latest |
Thanks Linus, can you make a doc PR too? https://github.com/valkey-io/valkey-doc The README file should provide most of what you need to know. If not, just reach out. |
DELIFEQ was added in valkey-io#1975 but had some issues. Do some refactoring to reduce the number of lines of code, write commands need to increment dirty and we can propagate it as DEL command. Signed-off-by: Binbin <binloveplay1314@qq.com>
Please also pick #2120.
This feature introduces a new command:
DELIFEQ key value
.The command deletes the given key only if its current value is equal to the provided
value
. It returns:This command complements
SET key value IFEQ match-value
, added in #1324.The problem/use-case that the feature addresses
A very common operation when synchronizing distributed locks is to remove a key, but only if the value matches a specific string. This pattern is frequently used in distributed locking algorithms like Redlock. The conditional delete prevents a client from inadvertently releasing a lock it doesn’t own—e.g., when a timeout or retry causes overlapping or stale attempts.
Today, this logic is typically implemented using a small Lua script like:
However, using scripts adds a layer of complexity and overhead. Having this logic as a built-in Redis command improves simplicity, reliability, and performance. It also complements
SET key IFEQ value
very nicely.Example: