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

# DIGEST

> Get the digest of a string value.

Use `DIGEST` to get the digest of a string value.

The reply is a 16-character lowercase hexadecimal XXH3 digest of the stored bytes, null when the key does not exist, and an error when the value is not a string. It is a fast non-cryptographic hash, meant for change detection rather than for security.

Comparing digests lets a client tell whether a large value has changed without transferring it, for instance to decide whether a cached copy is still current. The same digest can be passed to the conditional forms of [`SET`](/docs/redis/commands/string/set) (`IFDEQ`, `IFDNE`) and [`DELEX`](/docs/redis/commands/string/delex), which turns it into a compact compare-and-set token for large values. `DIGEST` is an Upstash extension.

## Syntax

```redis theme={"system"}
DIGEST <key>
```

## Arguments

| Argument | Required | Repeatable | Description |
| - | - | - | - |
| `key` | Yes | No | String key whose value should be hashed. |

## Important points

* The reply is a 16-character lowercase hexadecimal XXH3 digest of the stored string bytes.
* A missing key returns null. A key containing a non-string value returns `WRONGTYPE`.

## 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 | Bulk string or Null bulk string or null array |
| RESP3 | Bulk string or Null |

> [!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"}
> DIGEST lock:job-1
> ```

> **@upstash/redis**
>
> > [!NOTE]
> >
> > This command is not supported yet in `@upstash/redis`.

> **upstash\_redis**
>
> > [!NOTE]
> >
> > This command is not supported yet in `upstash_redis`.

> **ioredis**
>
> ```ts theme={"system"}
> import Redis from "ioredis";
>
> const redis = new Redis(process.env.REDIS_URL!);
> const result = await redis.call("DIGEST", "lock:job-1");
> 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.digest("lock:job-1");
> console.log(result);
> ```

> **redis-py**
>
> ```python theme={"system"}
> import os
> import redis
>
> client = redis.from_url(os.environ["REDIS_URL"])
> result = client.digest("lock:job-1")
> 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.Digest(context.Background(), "lock:job-1").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.digestKey("lock:job-1");
>   System.out.println(result);
> }
> ```

> **redis-rs**
>
> ```rust theme={"system"}
> use redis::TypedCommands;
>
> 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 result = connection.digest("lock:job-1")?;
>     println!("{result:?}");
>     Ok(())
> }
> ```


## Related topics

- [DELEX](/docs/redis/commands/string/delex.md)
- [EVALSHA](/docs/redis/commands/scripting/evalsha.md)
- [SET](/docs/redis/commands/string/set.md)
- [SCRIPT LOAD](/docs/redis/commands/scripting/script-load.md)
- [SCRIPT EXISTS](/docs/redis/commands/scripting/script-exists.md)


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