Skip to content
This repository has been archived by the owner on Sep 21, 2018. It is now read-only.

st-tech/redis-dist-mutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis::DistMutex

Distributed mutex using Redis.

Compatible with ruby Mutex. Enable to set expire to the lockfile. If set, act as like a setInterval in JavaScript.

Installation

Add this line to your application's Gemfile:

gem 'redis-dist-mutex', :git => 'https://github.com/vasilyjp/redis-dist-mutex.git'

Usage

setup

Redis::DistMutex.redis = Redis.new

synchoronize

mutex = Redis::DistMutex.new :app_name
mutex.synchronize { puts "act with lock" }

lock/unlock

mutex = Redis::DistMutex.new :app_name
begin
  mutex.lock
 puts "act with lock"
ensure
  mutex.unlock
end

Lock with expire (Set expire and autorelase)

mutex = Redis::DistMutex.new :app_name, expire: 1, autorelease: false
mutex.synchronize { puts "unlock after 1 sec." }

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages