> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# EVALSHA_RO

> Run a cached script that does not write.

Use `EVALSHA_RO` to run a script cached by its SHA1 digest. The script may not write to the database.

It is the read-only form of [`EVALSHA`](/docs/redis/commands/scripting/evalsha): any write command called from the script fails, which lets the server run it on replicas. As with `EVALSHA`, a digest that is not in the cache produces a `NOSCRIPT` error, and the caller is expected to fall back to [`EVAL_RO`](/docs/redis/commands/scripting/eval-ro) with the script body.

Read-only scripts take the global lock like any other script unless the cached body's shebang sets the `allow-key-locking` flag, for example `#!lua flags=no-writes,allow-key-locking`. With the flag, the call takes shared read locks on the [hash tag](/docs/redis/features/key-locking#hash-tags) of each key passed in `KEYS`. See [Key-Based Locking](/docs/redis/features/key-locking).

## Syntax

```redis theme={"system"}
EVALSHA_RO <sha1> <numkeys> [<key> [<key> ...]] [<arg> [<arg> ...]]
```

## Arguments

| Argument | Required | Repeatable | Description |
| - | - | - | - |
| `<sha1>` | Yes | No | SHA1 digest of a script cached with `SCRIPT LOAD`. |
| `<numkeys>` | Yes | No | Number of key arguments that follow. |
| `<key>` | No | Yes | Redis key targeted by the command. |
| `<arg>` | No | Yes | Additional argument, available to the script as `ARGV`. |

## 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 the cached body's shebang sets the `allow-key-locking` flag. See [Key-Based Locking](/docs/redis/features/key-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](/docs/redis/features/key-locking#dynamic-keys-and-latency).

## Reply conversion

`redis.setresp()` and the RESP2 and RESP3 conversions applied to `redis.call` replies work exactly as they do for [`EVAL`](/docs/redis/commands/scripting/eval#reply-conversion).

## 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.

| Protocol | Reply |
| - | - |
| RESP2 | Reply produced by the cached read-only script |
| RESP3 | Reply produced by the cached read-only script |

> [!NOTE]
>
> 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`.

> **Redis CLI**
>
> ```bash theme={"system"}
> EVALSHA_RO fb67a0c03b48ddbf8b4c9b011e779563bdbc28cb 0 value
> ```

> **@upstash/redis**
>
> ```ts theme={"system"}
> import { Redis } from "@upstash/redis";
>
> const redis = Redis.fromEnv();
>
> const result = await redis.evalshaRo("fb67a0c03b48ddbf8b4c9b011e779563bdbc28cb", [], ["hello"]);
> console.log(result) // "hello"
> ```

> **upstash\_redis**
>
> ```python theme={"system"}
> from upstash_redis import Redis
>
> redis = Redis.from_env()
> result = redis.evalsha_ro("<sha1>", args=["value"])
> print(result)
> ```

> **ioredis**
>
> ```ts theme={"system"}
> import Redis from "ioredis";
>
> const redis = new Redis(process.env.REDIS_URL!);
> const result = await redis.evalsha_ro("<sha1>", "0", "value");
> console.log(result);
> ```

> **node-redis**
>
> ```ts theme={"system"}
> import { createClient } from "redis";
>
> const client = await createClient({ url: process.env.REDIS_URL })
>   .on("error", console.error)
>   .connect();
> const result = await client.evalShaRo("<sha1>", { arguments: ["value"] });
> console.log(result);
> ```

> **redis-py**
>
> ```python theme={"system"}
> import os
> import redis
>
> client = redis.from_url(os.environ["REDIS_URL"])
> result = client.evalsha_ro("<sha1>", 0, "value")
> print(result)
> ```

> **go-redis**
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>
>     "github.com/redis/go-redis/v9"
> )
>
> func main() {
>     opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
>     if err != nil {
>         panic(err)
>     }
>     client := redis.NewClient(opts)
>     result, err := client.EvalShaRO(context.Background(), "<sha1>", nil, "value").Result()
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(result)
> }
> ```

> **jedis**
>
> ```java theme={"system"}
> import java.net.URI;
>
> import redis.clients.jedis.Jedis;
>
> try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
>   Object result = jedis.evalshaReadonly("<sha1>", java.util.List.of(), java.util.List.of("value"));
>   System.out.println(result);
> }
> ```

> **redis-rs**
>
> ```rust theme={"system"}
> fn main() -> redis::RedisResult<()> {
>     let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
>     let client = redis::Client::open(url)?;
>     let mut connection = client.get_connection()?;
>
>     let mut command = redis::cmd("EVALSHA_RO");
>     command.arg("<sha1>");
>     command.arg("1");
>     let result: redis::Value = command.query(&mut connection)?;
>     println!("{result:?}");
>     Ok(())
> }
> ```


## Related topics

- [EVALSHA_RO](/docs/redis/sdks/py/commands/scripts/evalsha_ro.md)
- [Changelog](/docs/redis/overall/changelog.md)
- [Key-Based Locking](/docs/redis/features/key-locking.md)
- [Pricing & Billing](/docs/redis/overall/billing.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.