eval.3valkey - Man Page

Executes a server-side Lua script.

Synopsis

EVAL script numkeys key [key...] arg [arg...]

Description

Invoke the execution of a server-side Lua script.

The first argument is the script’s source code. Scripts are written in Lua\c  and executed by the embedded valkey-lua-api(7) Lua 5.1 interpreter in Valkey.

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 valkey-lua-api(7) 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 redis-server, consuming a large amount of memory over time. Starting from Valkey 8.0, scripts loaded with EVAL or EVAL_RO will be deleted from redis after a certain number (least recently used order). The number of evicted scripts can be viewed through INFO’s evicted_scripts.

Please refer to the valkey-programmability(7) and valkey-eval-intro(7) Introduction to Eval Scripts for more information about Lua scripts.

Reply

The return value depends on the script that was executed.

Complexity

Depends on the script that is executed.

Acl Categories

@scripting @slow

History

Examples

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

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

See Also

evalsha(3valkey), evalsha_ro(3valkey), eval_ro(3valkey), fcall(3valkey), fcall_ro(3valkey), function(3valkey), function-delete(3valkey), function-dump(3valkey), function-flush(3valkey), function-help(3valkey), function-kill(3valkey), function-list(3valkey), function-load(3valkey), function-restore(3valkey), function-stats(3valkey), script(3valkey), script-debug(3valkey), script-exists(3valkey), script-flush(3valkey), script-help(3valkey), script-kill(3valkey), script-load(3valkey), script-show(3valkey)

Info

2024-09-23 8.0.0 Valkey Command Manual