EVAL(3valkey)
β¨ EVAL β the valkey manual, bestie edition β¨
okay so you're here for EVAL(3valkey)?? the command that runs your Lua scripts server-side?? say less, I got you π this is from the Valkey Command Manual and it's literally one of the most iconic scripting commands ever, no cap.
πΈ NAME πΈ
eval β executes a server-side Lua script.
π SYNOPSIS π
EVAL script numkeys key [key...] arg [arg...]
π DESCRIPTION π
So what you're doing here is invoking the execution of a server-side Lua script. simple as that. π
The first argument is the script's source code. Scripts are written in Lua and executed by the embedded valkey-lua-api(7) Lua 5.1 interpreter in Valkey. yes bestie, Lua 5.1, don't come at me with 5.4, that's not the vibe here.
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. like... this is not a suggestion, this is THE RULE, please don't break cluster mode π
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 toEVAL. These are added to the Lua interpreter and cached tovalkey-server, consuming a large amount of memory over time. Starting from Valkey 8.0, scripts loaded withEVALorvalkey-eval_ro(7)EVAL_ROwill be deleted from Valkey after a certain number (least recently used order). The number of evicted scripts can be viewed through theevicted_scriptsfield in the stats section of thevalkey-info(7)INFOcommand. so if your memory is looking kinda wild, check that field fr fr π
Please refer to the valkey-programmability(7) and valkey-eval-intro(7) Introduction to Eval Scripts for more information about Lua scripts. go read those, they're giving textbook but make it cute πβ¨
π REPLY π
The return value depends on the script that was executed. yeah. it's giving "whatever you asked for" energy. π¦
β COMPLEXITY β
Depends on the script that is executed. your script, your problem, bestie π
π ACL CATEGORIES π
@scripting@slow
π§ HISTORY π§
- Available since: 2.6.0
π EXAMPLES π
The following example will run a script that returns the first argument that it gets. iconic behavior honestly.
> EVAL "return ARGV[1]" 0 hello
"hello"
look at her go π
π 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)
okay that's the whole page, you ate that π«Ά this version is 9.0.0, dated 2025-10-21 β go forth and script responsibly, bestie, and remember: list your keys explicitly or the cluster will simply not forgive you π β¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms