delifeq.3valkey - Man Page

Delete key if value matches string.

Synopsis

DELIFEQ key value

Description

Deletes the key if its value matches the given string.

This command is typically used to safely release locks in distributed systems, ensuring that only the owner of the lock (as identified by the value) can delete it.

If the key exists and the stored value is a string that exactly matches the provided value, the key is removed and 1 is returned. Otherwise, the key is left unchanged and 0 is returned.

Reply

One of the following:

Complexity

O(1)

Acl Categories

@fast @string @write

History

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

Wrong value:

127.0.0.1:6379> SET mykey xyz789
OK
127.0.0.1:6379> DELIFEQ mykey abc123
(integer) 0

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

Use case: Safe lock release

DELIFEQ enables an atomic check-and-delete operation to safely release a lock only if the process still holds it. This avoids race conditions where a lock might expire and be claimed by another process before the original owner tries to delete it.

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.

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

See Also

See Also

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)

Info

2025-10-21 9.0.0 Valkey Command Manual