# HGETDEL

> Get the values of hash fields and delete those fields in one step.

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

```
HGETDEL key FIELDS numfields field [field ...]
```

- Group: Hash
- Complexity: O(N) where N is the number of fields given
- HotKV Cloud: all plans
- On-Premise: no license needed

`HGETDEL` returns the values of the listed fields of the hash at `key` and
removes those fields, atomically. Fields that do not exist give a nil and are
otherwise ignored. When the last field is removed, the key is deleted.

`FIELDS` must come right after the key, and `numfields` must equal the number
of field names that follow.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array with one entry per field: the value as a bulk string, or nil bulk string if the field did not exist | Array of bulk strings, with null for a missing field |
| Key does not exist | Array of nils, one per field | Array of nulls |

Errors:

- `WRONGTYPE` if `key` holds a value that is not a hash.
- `ERR Mandatory argument FIELDS is missing or not at the right position`.
- `ERR Number of fields must be a positive integer`.
- ``ERR The `numfields` parameter must match the number of arguments``.

## Examples

```
127.0.0.1:6379> HSET job:5 state "ready" owner "w1"
(integer) 2
127.0.0.1:6379> HGETDEL job:5 FIELDS 2 state missing
1) "ready"
2) (nil)
127.0.0.1:6379> HGETDEL job:5 FIELDS 1 owner
1) "w1"
127.0.0.1:6379> EXISTS job:5
(integer) 0
```

## Compatibility

Same as Redis 8.0. Redis 7.4 and Valkey 8 do not have this command.

## See also

[HGETEX](https://docs.hotkv.com/commands/hgetex/index.md), [HDEL](https://docs.hotkv.com/commands/hdel/index.md), [HMGET](https://docs.hotkv.com/commands/hmget/index.md),
[GETDEL](https://docs.hotkv.com/commands/getdel/index.md)