Class: Lita::Timing::Mutex
- Inherits:
-
Object
- Object
- Lita::Timing::Mutex
- Defined in:
- lib/lita/timing/mutex.rb
Constant Summary collapse
- LOCK_TIMEOUT =
seconds
30- DEL_SCRIPT =
<<-EOS if redis.call("get",KEYS[1]) == ARGV[1] then return redis.call("del",KEYS[1]) else return 0 end EOS
Instance Method Summary collapse
-
#initialize(name, redis) ⇒ Mutex
constructor
A new instance of Mutex.
- #syncronise(&block) ⇒ Object
Constructor Details
#initialize(name, redis) ⇒ Mutex
Returns a new instance of Mutex.
18 19 20 |
# File 'lib/lita/timing/mutex.rb', line 18 def initialize(name, redis) @name, @redis = name, redis end |
Instance Method Details
#syncronise(&block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/lita/timing/mutex.rb', line 22 def syncronise(&block) token = SecureRandom.hex(10) val = nil set_with_retry(@name, token, LOCK_TIMEOUT + 1) yield @redis.eval(DEL_SCRIPT, keys: [@name], argv: [token]) end |