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

# SCRIPT EXISTS

> Check if scripts exist in cache.

Use `SCRIPT EXISTS` to check which of the given SHA1 digests are present in the script cache.

The reply holds one `1` or `0` per digest, in the order they were given. Client libraries use it to find out, in a single call, which of their scripts still need to be loaded before they can be invoked with [`EVALSHA`](/docs/redis/commands/scripting/evalsha), instead of discovering the gap through a `NOSCRIPT` error at call time.

## Syntax

```redis theme={"system"}
SCRIPT EXISTS <sha1> [<sha1> ...]
```

## Arguments

| Argument | Required | Repeatable | Description                                        |
| -------- | -------- | ---------- | -------------------------------------------------- |
| `<sha1>` | Yes      | Yes        | SHA1 digest of a script cached with `SCRIPT LOAD`. |

## 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    | Array of integers, one per SHA1 digest |
| RESP3    | Array of integers, one per SHA1 digest |

<Note>
  Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
</Note>

## Examples

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

<AccordionGroup>
  <Accordion title="Redis CLI" icon="terminal">
    ```bash theme={"system"}
    SCRIPT EXISTS fb67a0c03b48ddbf8b4c9b011e779563bdbc28cb
    ```
  </Accordion>

  <Accordion title="@upstash/redis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import { Redis } from "@upstash/redis";

    const redis = Redis.fromEnv();

    await redis.scriptExists("<sha1>", "<sha2>")

    // Returns 1
    // [1, 0]
    ```
  </Accordion>

  <Accordion title="upstash_redis" icon="python" iconType="brands">
    ```python theme={"system"}
    from upstash_redis import Redis

    redis = Redis.from_env()
    result = redis.script_exists("<sha1>")
    print(result)
    ```
  </Accordion>

  <Accordion title="ioredis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import Redis from "ioredis";

    const redis = new Redis(process.env.REDIS_URL!);
    const result = await redis.script("EXISTS", "<sha1>");
    console.log(result);
    ```
  </Accordion>

  <Accordion title="node-redis" icon="node-js" iconType="brands">
    ```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.scriptExists("<sha1>");
    console.log(result);
    ```
  </Accordion>

  <Accordion title="redis-py" icon="python" iconType="brands">
    ```python theme={"system"}
    import os
    import redis

    client = redis.from_url(os.environ["REDIS_URL"])
    result = client.script_exists("<sha1>")
    print(result)
    ```
  </Accordion>

  <Accordion title="go-redis" icon="golang" iconType="brands">
    ```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.ScriptExists(context.Background(), "<sha1>").Result()
        if err != nil {
            panic(err)
        }
        fmt.Println(result)
    }
    ```
  </Accordion>

  <Accordion title="jedis" icon="java" iconType="brands">
    ```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.scriptExists("<sha1>");
      System.out.println(result);
    }
    ```
  </Accordion>

  <Accordion title="redis-rs" icon="rust" iconType="brands">
    ```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("SCRIPT");
        command.arg("EXISTS");
        command.arg("<sha1>");
        let result: redis::Value = command.query(&mut connection)?;
        println!("{result:?}");
        Ok(())
    }
    ```
  </Accordion>
</AccordionGroup>


## Related topics

- [SCRIPT EXISTS](/docs/redis/sdks/py/commands/scripts/script_exists.md)
- [Overview](/docs/redis/sdks/py/commands/overview.md)
- [EXISTS](/docs/redis/commands/generic/exists.md)
