Class: Wolverine::Script
- Inherits:
-
Object
- Object
- Wolverine::Script
- Defined in:
- lib/wolverine/script.rb
Overview
Defined Under Namespace
Classes: TemplateContext
Instance Method Summary collapse
-
#call(redis, *args) ⇒ Object
Passes the script and supplied arguments to redis for evaulation.
-
#initialize(file, options = {}) ⇒ Script
constructor
Loads the script file from disk and calculates its
SHA1
sum.
Constructor Details
#initialize(file, options = {}) ⇒ Script
Loads the script file from disk and calculates its SHA1
sum.
15 16 17 18 19 20 |
# File 'lib/wolverine/script.rb', line 15 def initialize file, = {} @file = Pathname.new(file) @config = [:config] || Wolverine.config @content = load_lua file @digest = Digest::SHA1.hexdigest @content end |
Instance Method Details
#call(redis, *args) ⇒ Object
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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wolverine/script.rb', line 33 def call redis, *args t = Time.now 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, @content) else raise end ensure StatsD.measure(statsd_key, (Time.now - t) * 1000, 0.001) if Wolverine.statsd_enabled? end |