Class: Resque::Plugins::Serializer::Mutex
- Inherits:
-
Object
- Object
- Resque::Plugins::Serializer::Mutex
- Defined in:
- lib/resque-serializer/mutex.rb
Defined Under Namespace
Classes: LockFailed
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#initialize(key, ttl: 5.minutes) ⇒ Mutex
constructor
A new instance of Mutex.
- #lock ⇒ Object
- #lock! ⇒ Object
- #locked? ⇒ Boolean
- #unlock ⇒ Object
Constructor Details
#initialize(key, ttl: 5.minutes) ⇒ Mutex
Returns a new instance of Mutex.
14 15 16 17 |
# File 'lib/resque-serializer/mutex.rb', line 14 def initialize(key, ttl: 5.minutes) @key = key @ttl = ttl.to_i end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/resque-serializer/mutex.rb', line 9 def key @key end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
9 10 11 |
# File 'lib/resque-serializer/mutex.rb', line 9 def ttl @ttl end |
Instance Method Details
#lock ⇒ Object
19 20 21 |
# File 'lib/resque-serializer/mutex.rb', line 19 def lock !!redis.set(key, true, ) end |
#lock! ⇒ Object
23 24 25 |
# File 'lib/resque-serializer/mutex.rb', line 23 def lock! !!redis.set(key, true, ) || fail(LockFailed) end |
#locked? ⇒ Boolean
27 28 29 |
# File 'lib/resque-serializer/mutex.rb', line 27 def locked? !!redis.get(key) end |
#unlock ⇒ Object
31 32 33 |
# File 'lib/resque-serializer/mutex.rb', line 31 def unlock !!redis.del(key) end |