DELEX deletes a key in Valkey® only if its value matches the one you give, so a worker can remove only what it owns. It’s new in Valkey 9.2. On 9.0 and 9.1, DELIFEQ does the matching part. This guide uses a job owned by worker-1.
Type the commands at the valkey-cli prompt. To open it, run valkey-cli in a terminal.
Note: Every command and output on this page is real, run on Valkey 9.2 on an Apple silicon Mac with macOS 26.
Syntax
DELEX key IFEQ value
DELEX key IFNE value
DELIFEQ key value
key: the key to delete. It must hold a string.IFEQ value: delete only if the key holds exactly this value.IFNE value: delete only if it holds anything else.DELIFEQ key value: the same asDELEX key IFEQ value.
Both reply 1 when the key was deleted and 0 when it wasn’t. From the DELEX (opens in a new tab) and DELIFEQ (opens in a new tab) documentation.
Prerequisites
- Valkey 9.2 or later for
DELEX.DELIFEQin Step 5 needs 9.0 or later.
Step 1: Save the Owner
SET job:owner "worker-1"
OK
Step 2: A Wrong Value Deletes Nothing
DELEX job:owner IFEQ "worker-2"
(integer) 0
GET job:owner
"worker-1"
0: the key holds worker-1, not worker-2, so it stays.
Step 3: The Right Value Deletes the Key
DELEX job:owner IFEQ "worker-1"
(integer) 1
GET job:owner
(nil)
Step 4: Delete Unless It Matches with IFNE
SET mode "test"
OK
DELEX mode IFNE "live"
(integer) 1
mode held test, not live, so IFNE deleted it.
Step 5: Do the Same on Valkey 9.0 and 9.1 with DELIFEQ
SET job:owner "worker-1"
OK
DELIFEQ job:owner "worker-1"
(integer) 1

Clean Up
Nothing to delete: the steps above deleted both keys.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Reading the value with GET, then deleting with DEL | Another client can change the key between the two commands, and you delete its value | Use DELEX … IFEQ, which checks and deletes in one step |
Using DELEX on a key that isn’t a string | Valkey replies with an error | Use it only on string keys |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
(error) ERR unknown command 'DELEX', with args beginning with: 'job:owner' 'IFEQ' 'worker-1' | Your Valkey is older than 9.2 | Use DELIFEQ, or upgrade to Valkey 9.2 or later |
FAQ
Why not GET the value and then DEL the key?
Another client could change the key between your two commands. The DELIFEQ documentation (opens in a new tab) calls the single-step check-and-delete the safe way to release a lock.
What does DELEX reply when the key doesn’t exist?
0, the same as when the value doesn’t match.
Conclusion
DELEX key IFEQ value deletes a key only when it holds that value, and IFNE only when it holds something else. On Valkey 9.0 and 9.1, use DELIFEQ.
Related
- Valkey Tutorial — Part 4: Strings and Counters
- Valkey Tutorial — Part 2: Your First Valkey Commands with valkey-cli
Additional Resources
Valkey® is a registered trademark of LF Projects, LLC. Redis® is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with the Valkey project, LF Projects or Redis Ltd., and isn’t endorsed, supported or certified by them.
0 comments