Module: Oxblood::Commands::Scripting

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/scripting.rb

Instance Method Summary collapse

Instance Method Details

#eval(script, numkeys, *keys_and_args) ⇒ Object

Execute a Lua script server side

Examples:

session.eval("return redis.call('set','foo','bar')", 0)
# => 'OK'
session.eval("return redis.call('set',KEYS[1],'bar')", 1, :foo)
# => 'OK'
session.eval("return 10", 0)
# => 10
session.eval("return {1,2,{3,'Hello World!'}}", 0)
# => [1, 2, [3, 'Hello World!']]
session.eval("return redis.call('get','foo')", 0)
# => 'bar'
session.eval("return {1,2,3.3333,'foo',nil,'bar'}", 0)
# => [1, 2, 3, 'foo']

See Also:


36
37
38
# File 'lib/oxblood/commands/scripting.rb', line 36

def eval(script, numkeys, *keys_and_args)
  run(:EVAL, script, numkeys, keys_and_args)
end

#evalsha(sha1, numkeys, *keys_and_args) ⇒ Object

Execute a Lua script server side


46
47
48
# File 'lib/oxblood/commands/scripting.rb', line 46

def evalsha(sha1, numkeys, *keys_and_args)
  run(:EVALSHA, sha1, numkeys, keys_and_args)
end

#script_debug(mode) ⇒ String, RError

Set the debug mode for executed scripts.


57
58
59
# File 'lib/oxblood/commands/scripting.rb', line 57

def script_debug(mode)
  run(:SCRIPT, :DEBUG, mode)
end

#script_exists(*sha1_digests) ⇒ Array<Integer>

Check existence of scripts in the script cache.


69
70
71
# File 'lib/oxblood/commands/scripting.rb', line 69

def script_exists(*sha1_digests)
  run(*sha1_digests.unshift(:SCRIPT, :EXISTS))
end

#script_flushString

Remove all the scripts from the script cache.


77
78
79
# File 'lib/oxblood/commands/scripting.rb', line 77

def script_flush
  run(:SCRIPT, :FLUSH)
end

#script_killString, RError

Kill the script currently in execution.


86
87
88
# File 'lib/oxblood/commands/scripting.rb', line 86

def script_kill
  run(:SCRIPT, :KILL)
end

#script_load(script) ⇒ String

Load the specified Lua script into the script cache.


97
98
99
# File 'lib/oxblood/commands/scripting.rb', line 97

def script_load(script)
  run(:SCRIPT, :LOAD, script)
end