Distributed mutex using Redis.
Compatible with ruby Mutex. Enable to set expire to the lockfile. If set, act as like a setInterval in JavaScript.
Add this line to your application's Gemfile:
gem 'redis-dist-mutex', :git => 'https://github.com/vasilyjp/redis-dist-mutex.git'
Redis::DistMutex.redis = Redis.new
mutex = Redis::DistMutex.new :app_name
mutex.synchronize { puts "act with lock" }
mutex = Redis::DistMutex.new :app_name
begin
mutex.lock
puts "act with lock"
ensure
mutex.unlock
end
mutex = Redis::DistMutex.new :app_name, expire: 1, autorelease: false
mutex.synchronize { puts "unlock after 1 sec." }
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request