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

Redis · Module

HGET

Returns the value of one field in a Redis hash. If the field or its hash key does not exist, Redis returns nil/null.

Since
2.0.0

How it works

HGET looks up one field in the hash stored at the specified key. Redis returns that field's string value when present; otherwise it returns a nil or null response when the field or key is absent.

Syntax

HGET key field

Parameters

NameTypeDescription
keykeyThe name of the key that holds the hash.
fieldfieldThe field whose value to retrieve.

Returns

A bulk string containing the field value, or a nil/null reply if the field is absent or the key does not exist.

Key points

  • HGET retrieves exactly one field value from a Redis hash.
  • The key selects the hash, while the field selects the value inside it.
  • An existing field is returned as a bulk string value.
  • Redis signals absence with a nil/null reply when either the field or hash key is missing.
  • The command is categorized as a read operation for hashes and as fast.

Common mistakes

  • A missing field and a missing hash key both produce a nil/null response, so callers must handle absence explicitly.

Example: Read a hash field

HSET user:42 name "Ada"
HGET user:42 name
HGET user:42 email

Stores a hash field, retrieves an existing value, then demonstrates the nil result for a missing field.

When to use it

Cache field lookup

Read one attribute from a cached object stored as a Redis hash.

Targeted application reads

Fetch a single counter, status, or metadata field without reading the complete hash.

Presence checks

Check whether a hash field exists by distinguishing a value response from nil/null.

Interview questions

QWhat does HGET do, and what does it return when the field is missing?

HGET reads one field from a Redis hash using the key and field arguments. Its average time complexity is O(1), and it returns a bulk string when the field exists or nil when it does not.

Follow-up: How would you read several fields? Use HMGET, which returns an array of values in the same order as the requested fields.

QWhat is the syntax and purpose of each argument?

The command syntax is HGET key field. The key identifies the hash, and field identifies the single hash field whose value should be retrieved.

Follow-up: What happens if the key contains a non-hash value? Redis reports a WRONGTYPE error rather than treating the value as a hash.

QWhy is HGET efficient for single-field reads?

HGET has O(1) complexity because it retrieves one hash field. It is therefore suitable for targeted reads when an application needs a single attribute rather than the whole hash.

Follow-up: What command retrieves every field and value? HGETALL does so, but its cost grows with the size of the hash.

  • HSET
  • HMGET
  • HGETALL

Source: HGET | Redis. Checked 2026-10-16.