Class: Redislock::Lock

Inherits:
Object
  • Object
show all
Defined in:
lib/redislock.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, &block) ⇒ Lock

Returns a new instance of Lock.



50
51
52
# File 'lib/redislock.rb', line 50

def initialize(key, &block)
  @key, @block = key, block
end

Instance Method Details

#callObject



62
63
64
65
66
67
68
69
# File 'lib/redislock.rb', line 62

def call 
  @block.call(self)
  return true
ensure
  if Redislock.redis.del(@key) != 1
    raise Error, "Lock was lost during run"
  end
end

#extend(seconds) ⇒ Object



58
59
60
# File 'lib/redislock.rb', line 58

def extend(seconds)
  Redislock.redis.incr(@key, seconds)
end

#relock(seconds) ⇒ Object



54
55
56
# File 'lib/redislock.rb', line 54

def relock(seconds)
  Redislock.redis.set(@key, Speedytime.current + seconds + 1)
end