DELIFEQ(3valkey)
β¨ DELIFEQ β¨
okay bestie, so this is a page from the valkey manual (section 3valkey), and it's about a little command called delifeq that is genuinely so underrated, like it's giving β¨atomic lock releaseβ¨ and we're obsessed π
π NAME π
delifeq β Delete key if value matches string. that's it, that's the whole vibe. no cap. π
πΈ SYNOPSIS πΈ
DELIFEQ key value
two things, that's all she needs. key and value. periodt. π
π¦ DESCRIPTION π¦
So here's the tea π: delifeq deletes the key if its value matches the given string.
Where this hits different is distributed systems, fr fr. You use it to safely release locks β because it makes sure that the only person who can delete that lock is the actual owner of the lock (and the owner is identified by the value). nobody else gets to touch it, iykyk π₯
The rules, laid out plain:
- If the key exists and the stored value is a string that exactly matches the provided value β the key gets removed and
1is returned. slay. π - Otherwise β the key is left completely unchanged and
0is returned. no drama, no deletion. π«Ά
π REPLY π
You get one of these:
valkey-protocol(7)Integer reply:1if the key was deleted. ate. πvalkey-protocol(7)Integer reply:0if the key was not deleted because it did not exist or the value was not equal to the provided value. π
β‘ COMPLEXITY β‘
constant time baby, she's fast, she's efficient, she's that girl π
π ACL CATEGORIES π
@fast @string @write
π HISTORY π
- Available since:
9.0.0
fresh out the oven, a newer icon β¨
π EXAMPLES π
Basic usage:
127.0.0.1:6379> SET mykey abc123
OK
127.0.0.1:6379> DELIFEQ mykey abc123
(integer) 1
127.0.0.1:6379> DELIFEQ mykey abc123
(integer) 0
first call: deleted, 1, iconic. second call: the key's already gone so it's a 0, we move on π
Wrong value:
127.0.0.1:6379> SET mykey xyz789
OK
127.0.0.1:6379> DELIFEQ mykey abc123
(integer) 0
value said xyz789, you asked about abc123... not a match, key stays, 0. it's giving "wrong person, blocked" π
Wrong type:
127.0.0.1:6379> SADD mykey somevalue
(integer) 1
127.0.0.1:6379> DELIFEQ mykey somevalue
(error) WRONGTYPE Operation against a key holding the wrong kind of value
key is a set, not a string β straight up error. we love a command that knows its boundaries π
π§ Use case: Safe lock release π§
DELIFEQ enables an atomic check-and-delete operation, so you can safely release a lock only if the process still holds it. This dodges race conditions where a lock might expire and get claimed by another process before the original owner even tries to delete it. nightmare scenario, avoided. π
This pattern is commonly used as part of distributed locking systems like valkey-distlock(7) Redlock, which previously relied on Lua scripting to implement this logic. With DELIFEQ, such a use case becomes more robust and idiomatic. glow up fr π
Instead of:
EVAL "if redis.call('GET',KEYS[1]) == ARGV[1] then return redis.call('DEL',KEYS[1]) else return 0 end" 1 mykey abc123
You can now use:
DELIFEQ mykey abc123
like?? look at the difference. one line. main character energy π
π SEE ALSO π
valkey-set(7)SET IFEQ β Sets the key only if it matches the given value. (the sibling, the counterpart, the other half of the duo π«Ά)
π SEE ALSO (again, bc there's more) π
append(3valkey), decr(3valkey), decrby(3valkey), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setex(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)
whole friend group right there, go say hi π
and that's the page bestie!! π version 9.0.0, dated 2025-10-21, from the DELIFEQ(3valkey) manual. go forth and release your locks safely, you absolute legend β¨ππ¦
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms