Advertisement
Beginner Redis, Hashes in Redis

How do you retrieve a single field or all fields from a Redis hash?

Short answer

You use HGET with a specific field name to retrieve just that one value, or HGETALL to retrieve every field and value pair stored in the hash at once, letting you either fetch a specific piece of information or the entire object depending on what your application needs.

Save Redis mock interview
Advertisement
AModel answer
You use HGET with a specific field name to retrieve just that one value, or HGETALL to retrieve every field and value pair stored in the hash at once, letting you either fetch a specific piece of information or the entire object depending on what your application needs.
Example

HGET user:100 email HGETALL user:100

Real-world example
A profile page uses HGETALL to fetch a user's entire profile at once for display, while a notification system uses HGET to quickly check just the user's email field when sending a message.
Likely follow-ups
  • Is HGETALL efficient for hashes with a very large number of fields?
  • What is the format of the data returned by HGETALL?
Related topics