class Promiscuous::BlackHole::Locker

Constants

LOCK_OPTIONS

Public Class Methods

new(key) click to toggle source
# File lib/promiscuous_black_hole/locker.rb, line 9
def initialize(key)
  @key = key
end

Public Instance Methods

with_lock(&block) click to toggle source
# File lib/promiscuous_black_hole/locker.rb, line 13
def with_lock(&block)
  begin
    lock.lock
    block.call
  ensure
    lock.try_unlock
  end
rescue Redis::Lock::Recovered
  retry
end

Private Instance Methods

lock() click to toggle source
# File lib/promiscuous_black_hole/locker.rb, line 26
def lock
  @lock ||= Redis::Lock.new(@key, LOCK_OPTIONS.merge(:redis => Promiscuous::Redis.connection))
end