Class: SyncMachine::RedisLock
- Inherits:
-
Object
- Object
- SyncMachine::RedisLock
- Defined in:
- lib/sync_machine/redis_lock.rb
Overview
General-purpose class for locking via Redis.
Instance Method Summary collapse
- #acquire(&block) ⇒ Object
- #acquired? ⇒ Boolean
-
#initialize(redis_key) ⇒ RedisLock
constructor
A new instance of RedisLock.
Constructor Details
#initialize(redis_key) ⇒ RedisLock
Returns a new instance of RedisLock.
4 5 6 7 |
# File 'lib/sync_machine/redis_lock.rb', line 4 def initialize(redis_key) @redis_key = redis_key @acquired = false end |
Instance Method Details
#acquire(&block) ⇒ Object
9 10 11 |
# File 'lib/sync_machine/redis_lock.rb', line 9 def acquire(&block) yield_and_release(block) if set_redis_key end |
#acquired? ⇒ Boolean
13 14 15 |
# File 'lib/sync_machine/redis_lock.rb', line 13 def acquired? @acquired end |