Skip to main content
Use EVAL_RO to run a Lua script that is not allowed to write. It behaves like EVAL, with <numkeys> splitting the arguments into the KEYS and ARGV tables, except that any write command called from the script fails with an error. Declaring the read-only intent lets the server serve the call on replicas and turns an accidental write into a clear error instead of an unexpected modification, which is worth doing for every script that only computes over existing data. Being read-only is not by itself enough to run concurrently with other commands: like EVAL, this command takes the global lock unless the script’s shebang sets the allow-key-locking flag. With the flag, the script takes shared read locks on the keys passed in KEYS, so several readers of the same key proceed together. Combine the two flags with a comma, as in #!lua flags=no-writes,allow-key-locking, and see Key-Based Locking for the full rules.

Syntax

Arguments

Important points

  • numkeys must equal the number of key arguments that immediately follow it; remaining arguments are available to the script or function as ordinary arguments.
  • A read-only script still takes the global lock unless its shebang sets the allow-key-locking flag. See Key-Based Locking.
  • Pass every key the script reads through KEYS whether or not allow-key-locking is set. A key built inside the script is read from disk under the lock when it is not in memory, and it is rejected outright when the flag is set. See Dynamic Keys and Latency.

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Related topics

EVAL_ROEVALSHA_RO