Redis Eval Command
The Redis Eval command uses the Lua interpreter to execute scripts.
Syntax
The basic syntax of the redis Eval command is as follows:
redis 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]
Parameter Description:
- script: the parameter is a Lua 5.1 script program. The script need not (and should not) be defined as a Lua function.
- numkeys: used to specify the number of key name parameters.
- key [key ...]: starting from the third parameter of EVAL, these are the Redis keys used in the script. These key name parameters can be accessed in Lua via the global variable KEYS array, using 1-based indexing (KEYS[1], KEYS[2], and so on).
- **arg [arg ...]**: additional parameters, accessed in Lua via the global variable ARGV array, in a similar way to the KEYS variable (ARGV[1], ARGV[2], and so on).
Available Version
= 2.6.0
Example
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"