Redis Script
Redis scripts are executed using the Lua interpreter. Redis 2.6 supports the Lua environment through an embedded interpreter. The commonly used command to execute 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 ...]
Examples
The following example demonstrates the working process of Redis scripts:
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 Script Commands
The following table lists the commonly used Redis script commands:
| No. | Command & Description |
|---|---|
| 1 | EVAL script numkeys key [key ...] arg [arg ...] Executes Lua scripts. |
| 2 | EVALSHA sha1 numkeys key [key ...] arg [arg ...] Executes Lua scripts. |
| 3 | SCRIPT EXISTS script [script ...] Checks whether the specified script has already been saved in the cache. |
| 4 | SCRIPT FLUSH Removes all scripts from the script cache. |
| 5 | SCRIPT KILL Kills the currently running Lua script. |
| 6 | SCRIPT LOAD script Adds the script to the script cache, but does not execute this script immediately. |