Class: Pecorino::Adapters::RedisAdapter::RedisScript

Inherits:
Object
  • Object
show all
Defined in:
lib/pecorino/adapters/redis_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(script_filename) ⇒ RedisScript

Returns a new instance of RedisScript.



11
12
13
14
# File 'lib/pecorino/adapters/redis_adapter.rb', line 11

def initialize(script_filename)
  @script_body = File.read(File.dirname(__FILE__) + "/redis_adapter/" + script_filename)
  @sha = Digest::SHA1.hexdigest(@script_body)
end

Instance Method Details

#load_and_eval(redis, keys, argv) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/pecorino/adapters/redis_adapter.rb', line 16

def load_and_eval(redis, keys, argv)
  redis.evalsha(@sha, keys: keys, argv: argv)
rescue Redis::CommandError => e
  if e.message.include? "NOSCRIPT"
    redis.script(:load, @script_body)
    retry
  else
    raise e
  end
end