Commit 0012ca7
authored
Add DELIFEQ command (#1975)
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:
- 1 if the key was removed (i.e., it existed and matched the value),
- 0 otherwise (key did not exist, or the value did not match).
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:
```lua
if redis.call("get",KEYS[1]) == ARGV[1] then
return redis.call("del",KEYS[1])
else
return 0
end
```
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:
```redis
SET foo test
DELIFEQ foo test # returns 1, key is deleted
SET foo nope
DELIFEQ foo test # returns 0, key remains
```
Signed-off-by: Linus Unnebäck <[email protected]>1 parent c551108 commit 0012ca7
File tree
5 files changed
+134
-0
lines changed- src
- commands
- tests/unit/type
5 files changed
+134
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10459 | 10459 | | |
10460 | 10460 | | |
10461 | 10461 | | |
| 10462 | + | |
| 10463 | + | |
| 10464 | + | |
| 10465 | + | |
| 10466 | + | |
| 10467 | + | |
| 10468 | + | |
| 10469 | + | |
| 10470 | + | |
| 10471 | + | |
| 10472 | + | |
| 10473 | + | |
| 10474 | + | |
| 10475 | + | |
| 10476 | + | |
| 10477 | + | |
| 10478 | + | |
| 10479 | + | |
| 10480 | + | |
| 10481 | + | |
| 10482 | + | |
| 10483 | + | |
| 10484 | + | |
| 10485 | + | |
| 10486 | + | |
10462 | 10487 | | |
10463 | 10488 | | |
10464 | 10489 | | |
| |||
11316 | 11341 | | |
11317 | 11342 | | |
11318 | 11343 | | |
| 11344 | + | |
11319 | 11345 | | |
11320 | 11346 | | |
11321 | 11347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3628 | 3628 | | |
3629 | 3629 | | |
3630 | 3630 | | |
| 3631 | + | |
3631 | 3632 | | |
3632 | 3633 | | |
3633 | 3634 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
387 | 413 | | |
388 | 414 | | |
389 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
759 | 780 | | |
760 | 781 | | |
761 | 782 | | |
| |||
0 commit comments