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

Redis · Module

HVALS

Returns all values stored in a Redis hash. Use it when field names are unnecessary; the result order is not guaranteed.

Since
2.0.0

How it works

HVALS reads the hash identified by key and returns the values of every field as an array. It does not return field names; use HGETALL when both fields and values are needed.

Syntax

HVALS key

Parameters

NameTypeDescription
keyRedis keyThe name of the key that holds the hash.

Returns

An array containing all values in the hash; an absent key returns an empty array.

Key points

  • HVALS retrieves every value from the hash named by the supplied key, without returning field names.
  • Its required argument is the key whose value is a Redis hash.
  • The command is read-only and does not modify the hash.
  • Execution cost grows linearly with the number of fields in the hash.
  • Redis classifies HVALS as a read operation on hashes and marks it as slow relative to constant-time commands.

Example: Read all hash values

HSET myhash field1 "Hello"
HSET myhash field2 "World"
HVALS myhash

Stores two fields in a hash, then returns their values.

When to use it

Extract hash values

An application needs every cached attribute value from a hash but does not need the attribute names.

Batch-read cached values

A service prepares a list of cached values for processing or display.

Order-independent verification

A test compares the contents of a hash independent of Redis's unspecified iteration order.

Interview questions

QWhat does HVALS return, and what is its complexity?

HVALS takes one hash key and returns all values stored in that hash. Its time complexity is O(N), where N is the number of hash fields.

Follow-up: How would you retrieve field names as well? Use HGETALL, which returns both fields and values.

QWhat is the syntax and behavior for a missing key?

The command is HVALS key. The key must identify a hash; the result is an array of values, and an absent key produces an empty array.

Follow-up: What should be done before calling HVALS if a key might contain another data type? Check or enforce the key's type, because a wrong type causes a Redis error.

QWhen should an application use HVALS instead of HGET?

HVALS is useful when only the values from a hash are needed, such as collecting cached record attributes without transferring field names. It is a read-only hash command.

Follow-up: When would HGET be preferable? Use HGET when one known field is needed, avoiding a full O(N) scan.

  • HSET
  • HGET
  • HGETALL
  • HMGET
  • HLEN

Source: HVALS | Docs - Redis. Checked 2026-10-16.