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

Redis · Module

HMGET

Returns the values of multiple fields from a Redis hash, preserving field order and representing missing fields with nil.

Since
2.0.0

How it works

HMGET reads several fields from the hash stored at key in one command. Redis returns one result for each requested field, preserving request order and using a nil value when a field is absent.

Syntax

HMGET key field [field ...]

Parameters

NameTypeDescription
keykeyThe name of the key that holds the hash.
field [field ...]field namesOne or more fields whose values to retrieve.

Returns

An array containing one value for each requested field, in request order; an absent field yields nil.

Key points

  • HMGET retrieves multiple values from a single hash.
  • The first argument identifies the hash to read.
  • The command accepts one or more field names after the key.
  • Execution cost grows linearly with the number of requested fields.
  • Results correspond positionally to the requested field order.

Example: Read selected hash fields

redis-cli HSET user:42 name Ada role engineer
redis-cli HMGET user:42 name role missing

The result contains values aligned with the requested fields; the missing field produces a nil entry.

When to use it

Selective hash reads

Read a selected subset of attributes from a hash without fetching unrelated fields.

Batch field retrieval

Fetch several values in one command to reduce client-server round trips.

Interview questions

QWhat does HMGET do, and what is its complexity?

HMGET retrieves multiple fields from one Redis hash using a single command. Its time complexity is O(N), where N is the number of requested fields.

Follow-up: How does it differ from HGETALL? HGETALL returns every field and value, while HMGET limits the response to the explicitly requested fields.

QIn what order does HMGET return values?

The returned values follow the same order as the fields in the request. This lets callers associate each result with its corresponding input field by position.

Follow-up: What happens for an absent field? Redis places a nil value at that field's corresponding result position.

QWhat are HMGET's required arguments and missing-field behavior?

The key must identify a hash, and the command requires at least one field name. Asking for a field that is not present returns nil rather than failing the entire command.

Follow-up: What if the key contains another Redis data type? The command reports a wrong-type error because HMGET operates on hashes.

  • HGET
  • HGETALL
  • HSET

Source: HMGET. Checked 2026-10-16.