Skip to content

Commit 75100df

Browse files
committed
Update distlock to use DELIFEQ
Signed-off-by: Linus Unnebäck <[email protected]>
1 parent 04538d9 commit 75100df

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

topics/distlock.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ To acquire the lock, the way to go is the following:
8484
The command will set the key only if it does not already exist (`NX` option), with an expire of 30000 milliseconds (`PX` option).
8585
The key is set to a value “my\_random\_value”. This value must be unique across all clients and all lock requests.
8686

87-
Basically the random value is used in order to release the lock in a safe way, with a script that tells Valkey: remove the key only if it exists and the value stored at the key is exactly the one I expect to be. This is accomplished by the following Lua script:
87+
Basically the random value is used in order to release the lock in a safe way, with a script that tells Valkey: remove the key only if it exists and the value stored at the key is exactly the one I expect to be.
88+
89+
In Valkey 9.0.0 and later, this can be done atomically using the built-in DELIFEQ command:
90+
91+
DELIFEQ resource_name my_random_value
92+
93+
In earlier versions of Valkey, the same behavior can be achieved using a Lua script:
8894

8995
if server.call("get",KEYS[1]) == ARGV[1] then
9096
return server.call("del",KEYS[1])

0 commit comments

Comments
 (0)