Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

HDEL

HDEL deletes one or more fields from a Redis hash. It ignores missing fields, removes the hash when no fields remain, and returns the number of fields actually deleted.

How it works

HDEL removes one or more named fields from the hash stored at a key. Missing fields do not affect the result, and Redis removes the key automatically when the last remaining field is deleted.

Syntax

HDEL key field [field ...]

Parameters

NameTypeDescription
keystringThe name of the key that holds the hash.
field [field ...]stringOne or more fields to delete from the hash.

Returns

An integer: the number of fields removed, excluding requested fields that did not exist.

Key points

  • Use HDEL to delete selected field-value pairs while leaving other fields in the same hash untouched.
  • Removing the final existing field also removes the parent hash key.
  • The command supports deleting multiple fields in one call.
  • The integer reply counts only fields that existed and were successfully removed.
  • Redis categorizes HDEL as a write operation on hashes and marks it as fast.

Common mistakes

  • Deleting a missing field is not an error and does not increase the returned count.
  • A missing hash key produces a zero result rather than an error.

Example: Remove fields from a hash

HSET user:42 name "Ada" role "admin"
HDEL user:42 role name
HGETALL user:42

Creates two hash fields, removes both, then shows that the hash is empty and has been deleted.

When to use it

Partial record updates

Remove obsolete or user-edited attributes from a hash without replacing the entire object.

Batch field removal

Delete several known hash fields in one request.

Automatic empty-hash cleanup

Clean up a hash and let Redis remove its key when the last field disappears.

Interview questions

QWhat does HDEL return?

HDEL removes the requested fields from a hash and returns the number of fields actually removed. Requested fields that were absent are excluded from that count.

Follow-up: What happens when the final field is removed? Redis deletes the hash key, so subsequent access treats it as nonexistent.

QWhat is the HDEL command syntax?

Its syntax is HDEL key field [field ...]. The command accepts one hash key and one or more fields in a single operation.

Follow-up: How would you remove fields from several unrelated hashes? Issue a separate HDEL command for each hash key; HDEL operates on one key per invocation.

QWhat is HDEL's time complexity?

HDEL has linear complexity in the number of fields supplied for deletion, shown as O(N) in the command example. It is classified as a write and hash command.

Follow-up: What determines N here? N is the number of fields passed to the command, not the total number of fields already stored in the hash.

  • HSET
  • HGET
  • HGETALL
  • HEXISTS
  • HGETDEL
  • DEL

Source: HDEL. Checked 2026-10-16.