Skip to content

zoer/slock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slock

Code Climate Inline docs Gem Version

Slock implements Semaphore via Redis.

Installation

Add this line to your application's Gemfile:

gem 'slock'

Usage

Singleton Class

class MySemaphore
  include Slock::Semaphore::Singleton

  SIZE     = 2   # max count of simultaneous locks
  LIFETIME = 600 # max time that lock lives after acquring (in seconds)
  TIMEOUT  = 900 # max time that semaphore waits for lock to acquire before raising an error

  def semaphore_opts
    {
      redis:    Redis.new(url: ENV['REDIS_URL']),
      size:     SIZE,
      lifetime: LIFETIME,
      timeout:  TIMEOUT
    }
  end
end

MySemaphore.acquire { do_something }

Simple

sempahore = Slock::Semaphore.new 'uniq_semaphore_key',
  redis: Redis.new(ENV['REDIS_URL']),
  lifetime: 600,
  timeout: 900

semaphore.acquire { do_something }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages