Back to Redis

HGETDEL

content/commands/hgetdel.md

latest1.4 KB
Original Source

Get and delete the value of one or more fields of a given hash key. When the last field is deleted, the key will also be deleted.

Example

redis> HSET mykey field1 "Hello" field2 "World" field3 "!"
(integer) 3
redis> HGETALL mykey
1) "field1"
2) "Hello"
3) "field2"
4) "World"
5) "field3"
6) "!"
redis> HGETDEL mykey FIELDS 2 field3 field4
1) "!"
2) (nil)
redis> HGETALL mykey
1) "field1"
2) "Hello"
3) "field2"
4) "World"
redis> HGETDEL mykey FIELDS 2 field1 field2
1) "Hello"
2) "World"
redis> KEYS *
(empty array)

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="hgetdel-return-info" tab1="RESP2" tab2="RESP3" >}}

Array reply: a list of deleted fields and their values or nil for fields that do not exist.

-tab-sep-

Array reply: a list of deleted fields and their values or nil for fields that do not exist.

{{< /multitabs >}}