Class: Reqless::LuaScript
- Inherits:
-
Object
- Object
- Reqless::LuaScript
- Defined in:
- lib/reqless/lua_script.rb
Overview
Wraps a lua script. Knows how to reload it if necessary
Direct Known Subclasses
Defined Under Namespace
Modules: ScriptNotLoadedRedisCommandError
Constant Summary collapse
- DEFAULT_ON_RELOAD_CALLBACK =
proc {}
- SCRIPT_ROOT =
File.('../lua', __FILE__)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
Instance Method Summary collapse
- #call(*argv) ⇒ Object
-
#initialize(name, redis, options = {}) ⇒ LuaScript
constructor
A new instance of LuaScript.
- #reload ⇒ Object
Constructor Details
#initialize(name, redis, options = {}) ⇒ LuaScript
Returns a new instance of LuaScript.
13 14 15 16 17 18 |
# File 'lib/reqless/lua_script.rb', line 13 def initialize(name, redis, = {}) @name = name @on_reload_callback = [:on_reload_callback] || DEFAULT_ON_RELOAD_CALLBACK @redis = redis @sha = Digest::SHA1.hexdigest(script_contents) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/reqless/lua_script.rb', line 20 def name @name end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
20 21 22 |
# File 'lib/reqless/lua_script.rb', line 20 def redis @redis end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
20 21 22 |
# File 'lib/reqless/lua_script.rb', line 20 def sha @sha end |
Instance Method Details
#call(*argv) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reqless/lua_script.rb', line 28 def call(*argv) handle_no_script_error do _call(*argv) end rescue Redis::CommandError => err if match = err..match('user_script:\d+:\s*(\w+.+$)') raise LuaScriptError.new(match[1]) else raise err end end |
#reload ⇒ Object
22 23 24 25 26 |
# File 'lib/reqless/lua_script.rb', line 22 def reload @sha = @redis.script(:load, script_contents) @on_reload_callback.call(@redis, @sha) @sha end |