class Resque::Plugins::Serializer::Mutex
Attributes
key[R]
ttl[R]
Public Class Methods
new(key, ttl: 5.minutes)
click to toggle source
# File lib/resque-serializer/mutex.rb, line 14 def initialize(key, ttl: 5.minutes) @key = key @ttl = ttl.to_i end
Public Instance Methods
lock()
click to toggle source
# File lib/resque-serializer/mutex.rb, line 19 def lock !!redis.set(key, true, set_options) end
lock!()
click to toggle source
# File lib/resque-serializer/mutex.rb, line 23 def lock! !!redis.set(key, true, set_options) || fail(LockFailed) end
locked?()
click to toggle source
# File lib/resque-serializer/mutex.rb, line 27 def locked? !!redis.get(key) end
unlock()
click to toggle source
# File lib/resque-serializer/mutex.rb, line 31 def unlock !!redis.del(key) end
Private Instance Methods
set_options()
click to toggle source
# File lib/resque-serializer/mutex.rb, line 37 def set_options { nx: true, px: ttl * 1000 # msecs } end