DEV Community

Kohki Chau
Kohki Chau

Posted on

Redis Distributed Lock Tips

  1. The algorithm requires a minimum of three Redis instances to work.
  2. The client generates a random value called nonce and tries to acquire a lock on a resource by sending a SET command to each of the Redis instances with the same resource_name and nonce values.
  3. The SET command should include an EX parameter to set an expiration time for the lock.
  4. If the client can acquire the lock on a majority of the Redis instances, it is considered to have acquired the lock.
  5. If the client fails to acquire the lock on a majority of the Redis instances, it should release the lock on all the instances where it was acquired.
  6. To release the lock, the client sends a DEL command to all the Redis instances where it had acquired the lock.

The Redlock algorithm is designed to provide mutual exclusion, deadlock-free and fault-tolerant guarantees

Top comments (0)