Upstash Documentation

DIGEST

Get the digest of a string value.
2 min read

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#

ArgumentRequiredRepeatableDescription
keyYesNoString 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.

ProtocolReply
RESP2Bulk string or Null bulk string or null array
RESP3Bulk 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
@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
node-redis
redis-py
go-redis
jedis
redis-rs