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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay