Class: Wolverine::Script
- Inherits:
-
Object
- Object
- Wolverine::Script
- Defined in:
- lib/wolverine/script.rb
Overview
Instance Method Summary (collapse)
-
- (Object) call(redis, *args)
Passes the script and supplied arguments to redis for evaulation.
-
- (Script) initialize(file)
constructor
Loads the script file from disk and calculates its SHA1 sum.
Constructor Details
- (Script) initialize(file)
Loads the script file from disk and calculates its SHA1 sum.
14 15 16 17 18 |
# File 'lib/wolverine/script.rb', line 14 def initialize file @file = Pathname.new(file) @content = load_lua file @digest = Digest::SHA1.hexdigest @content end |
Instance Method Details
- (Object) call(redis, *args)
Passes the script and supplied arguments to redis for evaulation. It first attempts to use a script redis has already cached by using the EVALSHA command, but falls back to providing the full script text via EVAL if redis has not seen this script before. Future invocations will then use EVALSHA without erroring.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wolverine/script.rb', line 31 def call redis, *args begin run_evalsha redis, *args rescue => e e. =~ /NOSCRIPT/ ? run_eval(redis, *args) : raise end rescue => e if LuaError.intercepts?(e) raise LuaError.new(e, @file) else raise end end |