Sha256: c0ad3ec8eec9264472e3cce516bbd6a4d9887c4087dd7e23b627d4b5f15fc65f
Contents?: true
Size: 722 Bytes
Versions: 2
Compression:
Stored size: 722 Bytes
Contents
require 'openssl' class Redis module Scripting class Script attr_reader :source_filename, :source, :name def initialize(source_filename, opts = {}) @source_filename = source_filename @source = File.read(source_filename) if opts[:script_header] @source = "#{opts[:script_header]}\n\n#{@source}" end @name = File.basename(source_filename, ".lua") end def run(redis, keys, argv) begin redis.evalsha(self.sha, keys: keys, argv: argv) rescue Redis::CommandError => err raise unless err.message.start_with?("NOSCRIPT") redis.eval(self.source, keys: keys, argv: argv) end end def sha @sha ||= OpenSSL::Digest::SHA1.hexdigest(source) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
redis-scripting-1.0.1 | lib/redis/scripting/script.rb |
redis-scripting-1.0.0 | lib/redis/scripting/script.rb |