Class: Redis::Lock::Script
- Inherits:
-
Object
- Object
- Redis::Lock::Script
- Defined in:
- lib/robust-redis-lock/script.rb
Instance Method Summary collapse
- #eval(redis, options = {}) ⇒ Object
-
#initialize(script) ⇒ Script
constructor
A new instance of Script.
- #to_s ⇒ Object
Constructor Details
#initialize(script) ⇒ Script
Returns a new instance of Script.
2 3 4 5 |
# File 'lib/robust-redis-lock/script.rb', line 2 def initialize(script) @script = script @sha = Digest::SHA1.hexdigest(@script) end |
Instance Method Details
#eval(redis, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/robust-redis-lock/script.rb', line 7 def eval(redis, ={}) redis.evalsha(@sha, ) rescue ::Redis::CommandError => e if e. =~ /^NOSCRIPT/ redis.script(:load, @script) retry end if e. =~ /^ERR unknown command/ raise "You are using a version of Redis that does not support LUA scripting. Please use Redis 2.6.0 or greater" end raise e end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/robust-redis-lock/script.rb', line 20 def to_s @script end |