Sha256: bb451b03c90d5a70c24b0ee2040b6931a424b376678823b1a3cc682262b71583

Contents?: true

Size: 591 Bytes

Versions: 2

Compression:

Stored size: 591 Bytes

Contents

require 'digest/sha1'

module Wolverine
  class Script
    attr_reader :content, :digest
    def initialize file
      @content = load_lua file
      @digest = Digest::SHA1.hexdigest @content
    end

    def call redis, *args
      run_evalsha redis, *args
    rescue => e
      e.message =~ /NOSCRIPT/ ? run_eval(redis, *args) : raise
    end

    private

    def run_evalsha redis, *args
      redis.evalsha digest, args.size, *args
    end

    def run_eval redis, *args
      redis.eval content, args.size, *args
    end

    def load_lua file
      File.read file
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wolverine-0.1.1 lib/wolverine/script.rb
wolverine-0.1.0 lib/wolverine/script.rb