A distributed lock coordinates access to a shared resource across multiple processes/servers so only one holds the lock at a time. Redis is commonly used for this via atomic set-if-not-exists with a TTL — though doing it correctly requires care (and understanding the limitations).
A basic Redis lock (SET NX with TTL)
token = ();
acquired = redis.(, token, , , );
(acquired) {
{
} {
(, token);
}
}
