Upstash Documentation

GETDEL

Get value and delete key.
2 min read

Use GETDEL to read the value of a key and delete the key in the same atomic step.

The reply is the value, or null when the key does not exist, and an error when the value is not a string. Because nothing can run between the read and the delete, exactly one caller can obtain the value, which is what makes it right for one-shot data such as a one-time token, a password reset code, or a handoff between two processes. It replaces the GET plus DEL pair and its race.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.

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
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs