EVAL

EVAL script numkeys [key [key ...]] [arg [arg ...]]
Available since:
Redis Open Source 2.6.0
Time complexity:
Depends on the script that is executed.
ACL categories:
@slow, @scripting,
Compatibility:
Redis Software and Redis Cloud compatibility
Note:
This command's behavior varies in clustered Redis environments. See the multi-key operations page for more information.

Executes a server-side Lua script with the embedded Redis Lua 5.1 interpreter. The first argument is the script’s source code.

The second argument is the number of input key name arguments, followed by all the keys accessed by the script. These input key names are made 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 keys that a script accesses must be explicitly provided as input key arguments. Scripts 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 arguments, thus generating a different script on each call to EVAL. These values are added to the Lua interpreter and cached in Redis, consuming a large amount of memory over time.

Starting with Redis 7.4, Redis evicts scripts loaded with EVAL or EVAL_RO from the script cache when the cache reaches a certain size. Redis evicts the least recently used scripts first. You can view the number of evicted scripts with the evicted_scripts field in INFO.

Please refer to the Redis Programmability and Introduction to Eval Scripts for more information about Lua scripts.

Required arguments

script

The Lua script to evaluate.

numkeys

The number of key names that follow. Arguments after the keys are passed as regular arguments.

Optional arguments

key [key ...]

The key names the script accesses, provided to it via the Lua global KEYS runtime variable. There must be exactly numkeys of them.

arg [arg ...]

Additional arguments provided to the script via the Lua ARGV variable.

Examples

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

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

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Active-Active
✅ Standard
✅ Active-Active

Return information

The return value depends on the script that was executed.
RATE THIS PAGE
Back to top ↑