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 (IFDEQ, IFDNE) and DELEX, which turns it into a compact compare-and-set token for large values. DIGEST is an Upstash extension.
Syntax#
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 |
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
@upstash/redis
This command is not supported yet in @upstash/redis.
upstash_redis
This command is not supported yet in upstash_redis.