EVAL

EVAL

EVAL script numkeys [key] [arg]
Available since
2.6.0
Time complexity
Depends on the script that is executed.
ACL categories
@slow, @scripting

Invoke the execution of a server-side Lua script.

The first argument is the script’s source code. Scripts are written in Lua and executed by the embedded Lua 5.1 interpreter in Redict.

The second argument is the number of input key name arguments, followed by all the keys accessed by the script. These names of input keys are available to the script as the KEYS global runtime variable Any additional input arguments should not represent names of keys.

Important: to ensure the correct execution of scripts, both in standalone and clustered deployments, all names of keys that a script accesses must be explicitly provided as input key arguments. The script should only access keys whose names are given as input arguments. Scripts should never access keys with programmatically-generated names or based on the contents of data structures stored in the database.

Note: in some cases, users will abuse Lua EVAL by embedding values in the script instead of providing them as argument, and thus generating a different script on each call to EVAL. These are added to the Lua interpreter and cached to redict-server, consuming a large amount of memory over time. Starting from Redict 8.0, scripts loaded with EVAL or EVAL_RO will be deleted from redict after a certain number (least recently used order). The number of evicted scripts can be viewed through INFO’s evicted_scripts.

Please refer to Scripting Redict with Lua for more information about Lua scripts.

Examples #

The following example will run a script that returns the first argument that it gets.

> EVAL "return ARGV[1]" 0 hello
"hello"

Redict logo courtesy of @janWilejan, CC-BY-SA-4.0. Download SVG ⤑

Portions of this website courtesy of Salvatore Sanfilippo, CC-BY-SA-4.0.