Module: Hivent::Redis::Extensions

Included in:
Consumer, Producer
Defined in:
lib/hivent/redis/extensions.rb

Constant Summary collapse

LUA_CACHE =
Hash.new { |h, k| h[k] = Hash.new }

Instance Method Summary collapse

Instance Method Details

#script(file, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hivent/redis/extensions.rb', line 10

def script(file, *args)
  cache = LUA_CACHE[@redis.client.options[:url]]

  sha = if cache.key?(file)
          cache[file]
        else
          cache[file] = @redis.script("LOAD", File.read(file))
        end

  @redis.evalsha(sha, [], args)
end