# GETDEL

> Return the string value of a key and delete the key.

URL: https://docs.hotkv.com/commands/getdel/

```
GETDEL key
```

- Group: String
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`GETDEL` reads the string at `key` and deletes the key in the same step, so
no other client can read the value in between. Use it to consume one-time
values such as tokens.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The key held a string | Bulk string: the value | Bulk string |
| The key does not exist | Nil bulk string | Null |

`GETDEL` replies with a `WRONGTYPE` error, and deletes nothing, when the key
holds a value that is not a string.

## Examples

```
127.0.0.1:6379> SET otp:42 "839201"
OK
127.0.0.1:6379> GETDEL otp:42
"839201"
127.0.0.1:6379> GETDEL otp:42
(nil)
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[GET](https://docs.hotkv.com/commands/get/index.md), [GETEX](https://docs.hotkv.com/commands/getex/index.md), [DEL](https://docs.hotkv.com/commands/del/index.md)