module Redis::Lua
Constants
- Version
Public Instance Methods
register_script(name, text)
click to toggle source
# File lib/redis/lua.rb, line 28 def register_script(name, text) script = Script.new(name, text) scripts << script script end
register_script_files(glob)
click to toggle source
# File lib/redis/lua.rb, line 34 def register_script_files(glob) Dir[glob].map do |filename| script_name = filename.split('/').last.split('.').first register_script script_name, File.read(filename) end end
run_script(name, *args)
click to toggle source
# File lib/redis/lua.rb, line 8 def run_script(name, *args) raise "Nonexistent Lua script!" unless s = scripts.find { |script| script.name == name } case @client when Client begin evalsha s.sha, *args rescue CommandError => e raise unless e.message =~ /\ANOSCRIPT/ script :load, s.text evalsha s.sha, *args end when Pipeline # When pipelining or in a transaction block, an error will abort the # whole thing and there's no way to check whether the script has # already been loaded. So, to be safe, just eval the script text. eval s.text, *args end end
scripts()
click to toggle source
# File lib/redis/lua.rb, line 41 def scripts @scripts ||= [] end