Friday, September 12, 2014

Easy distributed locks using Redis

0 comments
Wombat is a very concurrent application. It runs on multiple hosts, processes and threads, and sometimes we need to lock an execution to be exclusively performed across all threads, no matter the host or process. As any other distributed application, we can’t use a simple Ruby Mutex, so we implemented a Mutex using Redis, which can be shared across all threads.

We decided to use Redis, because it’s fast, consistent and has two super useful commands for locking: SETNX and EXPIRE


  • SETNX sets the value of a key, only if the key does not exist. 
  • EXPIRE sets a key’s time to live in seconds. 
Basically the setnx returns true or false if the lock was acquired or not and the expire releases the lock after a specified ttl if the unlock wasn’t called.

Read more here

Leave a Reply

 
All Tech News IN © 2011 DheTemplate.com & Main Blogger .