Class: Redislock::Lock
- Inherits:
-
Object
- Object
- Redislock::Lock
- Defined in:
- lib/redislock.rb
Instance Method Summary collapse
- #call ⇒ Object
- #extend(seconds) ⇒ Object
-
#initialize(key, &block) ⇒ Lock
constructor
A new instance of Lock.
- #relock(seconds) ⇒ Object
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
#call ⇒ Object
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 |