Simple distributed locks with Redis.
gem install distributed_mutexOr you can install via Bundler if you are using Rails. Add this line to your application's Gemfile:
gem 'distributed_mutex'And then execute:
bundleredis = Redis.new
key = "foo:bar"
mutex = DistributedMutex.new(redis, key)
# Not wait for a lock
mutex.synchronize { 1 + 1 == 2 }
# Wait for a lock
mutex.synchronize(wait: true) { 1 + 1 == 2 }
# Extend a existed lock
mutex.extend_lock(100)git clone https://github.com/Dounx/distributed_mutex
cd distributed_mutex
gem build distributed_mutex.gemspec
gem install --local distributed_mutex-*.gemList of available tasks.
rake --tasksDistributedMutex is an open-sourced software licensed under the MIT license.