English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Eval Command

Redis Scripts

Redis Eval Command uses the Lua interpreter to execute scripts.

Syntax

Basic Syntax of Redis Eval Command:

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

Parameter Description:

  • script: The parameter is a segment of Lua 5.1 Script program. The script does not need (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, indicating the Redis keys (key) used in the script, these key name parameters can be accessed in Lua through the global variable KEYS array, using 1 : Access in the form of base address (KEYS[1], KEYS[2], etc).

  • arg [arg ...]: Additional parameters, accessed in Lua through the global variable ARGV array, in a similar manner to KEYS (ARGV[1], ARGV[2] , such as these).

Available Version

>= 2.6.0

Online Examples

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 Scripts