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']

Parameters:

  • script (String)
  • numkeys (Integer)
  • keys_and_args (String, Array<String>)

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

Parameters:

  • sha1 (String)
  • numkeys (Integer)
  • keys_and_args (String, Array<String>)

See Also:



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.

Parameters:

  • mode (Symbol)

Returns:

  • (String)

    ‘OK’

  • (RError)

    if wrong mode passed

See Also:



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.

Parameters:

  • sha1_digests (String, Array<String>)

Returns:

  • (Array<Integer>)

    For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 is returned, otherwise 0 is returned.

See Also:



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.

Returns:

  • (String)

    ‘OK’

See Also:



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.

Returns:

  • (String)

    ‘OK’

  • (RError)

    if there is no script to kill

See Also:



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.

Parameters:

  • script (String)

Returns:

  • (String)

    This command returns the SHA1 digest of the script added into the script cache

See Also:



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

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