Upstash Documentation

HGETDEL

Get and delete hash fields.
2 min read

Use HGETDEL to read hash fields and delete them in the same atomic step.

The reply holds the previous value of each requested field, in the order requested, with null for fields that were not present. Reading and removing together removes the race that an HGET followed by an HDEL would leave open, which makes the command a good fit for one-shot values such as one-time codes, claim tickets, or queued items keyed by name: exactly one caller gets the value.

FIELDS <numfields> introduces the field list and the count must match. The key is deleted when its last field is removed.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.
FIELDS <numfields> <field> [<field> ...]YesNoFields to target. Give the field count first, then that many field names.

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
RESP2Array of bulk-string values or null values, one per field
RESP3Array of bulk-string values or null values, one per field
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
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs