You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: topics/distlock.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,13 @@ To acquire the lock, the way to go is the following:
84
84
The command will set the key only if it does not already exist (`NX` option), with an expire of 30000 milliseconds (`PX` option).
85
85
The key is set to a value “my\_random\_value”. This value must be unique across all clients and all lock requests.
86
86
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:
0 commit comments