0
0
Redisquery~5 mins

HDEL for field removal in Redis

Choose your learning style9 modes available
Introduction
HDEL removes one or more fields from a hash in Redis. It helps keep your data clean by deleting unwanted parts.
You want to delete a specific detail from a user's profile stored as a hash.
You need to remove outdated settings from a configuration hash.
You want to clear a field from a product's information without deleting the whole product.
You want to update a hash by removing fields that are no longer relevant.
Syntax
Redis
HDEL key field [field ...]
You can remove one or multiple fields at once by listing them after the key.
If a field does not exist, Redis ignores it without error.
Examples
Removes the 'name' field from the hash stored at 'user:1000'.
Redis
HDEL user:1000 name
Removes both 'timeout' and 'retries' fields from the 'config' hash.
Redis
HDEL config timeout retries
Deletes the 'description' field from the product hash.
Redis
HDEL product:2000 description
Sample Program
First, we create a hash 'user:1' with three fields. Then we remove the 'age' field. Finally, we get all remaining fields to see the result.
Redis
HMSET user:1 name "Alice" age "30" city "Paris"
HDEL user:1 age
HGETALL user:1
OutputSuccess
Important Notes
HDEL returns the number of fields it actually removed.
If you try to remove a field that does not exist, it does not cause an error.
Use HGETALL after HDEL to verify which fields remain in the hash.
Summary
HDEL deletes specified fields from a Redis hash.
You can remove one or many fields at once.
It helps keep your hash data tidy by removing unwanted fields.