Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Scripting

Redis Scripting

Redis scripting uses the Lua interpreter to execute scripts. Redis 2.6 added embedded support for the Lua environment. The common command for executing scripts is EVAL.

Syntax

The basic syntax of the Eval command is as follows:



redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]

Example

The following example demonstrates the working process of redis scripting:



redis 127.0.0.1:6379> EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second



1) "key1"

2) "key2"

3) "first"

4) "second"


Redis Scripting Commands

The table below lists the common redis scripting commands:

No. Command and Description
1 EVAL script numkeys key [key ...] arg [arg ...]
Execute a Lua script.
2 EVALSHA sha1 numkeys key [key ...] arg [arg ...]
Execute a Lua script.
3 SCRIPT EXISTS script [script ...]
Check whether the specified script has been saved in the cache.
4 SCRIPT FLUSH
Remove all scripts from the script cache.
5 SCRIPT KILL
Kill the currently running Lua script.
6 SCRIPT LOAD script
Add the script to the script cache, but do not execute it immediately.