Pick the fix
Which release is safe?
Hint 1 of 1
What if our lock already expired and someone else holds it?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A Lua script that deletes the key only if its value equals our random token
Correct. Compare and delete happen atomically on the server.
Each holder stores a random token as the lock value. Releasing must check it is still our token and delete in one atomic step, which a Lua script does on the server.
Why not the others?
- B
DEL lock:job. Can delete a lock another worker acquired after ours expired. - C
GET lock:jobin the app, thenDELif it matches. Two round trips: the lock can change hands in between. - D Let it expire; never release. Safe but slow: other workers wait the full expiry.