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

Redis · Module

HKEYS

HKEYS returns all field names in the hash stored at a key. It returns an empty list when the key does not exist and has O(N) complexity based on the hash size.

Since
2.0.0

How it works

HKEYS reads the hash stored at a key and returns every field name without returning field values. It performs work proportional to the number of fields, and a missing key produces an empty list.

Syntax

HKEYS key

Parameters

NameTypeDescription
keykeyThe Redis key that stores the hash whose field names should be returned.

Returns

An array containing the hash's field names; it is empty if the key does not exist.

Key points

  • HKEYS lists every field name belonging to the hash at the supplied key.
  • Runtime grows linearly with the number of fields in the hash.
  • Its sole argument is the key containing the target hash.
  • Clients receive the result as an array-like list of field names.
  • Redis Open Source has supported HKEYS since version 2.0.0.

Common mistakes

  • A nonexistent key is not an error; Redis returns an empty list.

Example: List hash fields

import { createClient } from "redis";

const client = createClient();
await client.connect();

await client.hSet("user:42", { name: "Ada", role: "engineer" });
const fields = await client.hKeys("user:42");
console.log(fields); // ["name", "role"]

await client.quit();

Creates a hash, then retrieves only its field names with HKEYS.

When to use it

Inspect available hash fields

An application needs to discover which attributes are present before fetching selected values.

Expose cached object schema

A cache stores an object as a Redis hash and a UI or API needs its attribute names.

Audit hash contents

A maintenance task checks the fields currently stored in a hash without retrieving their values.

Interview questions

QWhat does HKEYS return?

HKEYS takes one hash key and returns an array containing all field names in that hash. It does not return the associated values.

Follow-up: What is its complexity? It is O(N), where N is the number of fields in the hash, so it may be expensive for large hashes.

QWhat is the syntax of HKEYS?

The command is HKEYS key. The key identifies the Redis hash whose field names should be listed.

Follow-up: How would you retrieve both names and values? Use HGETALL, while HKEYS is appropriate when only names are needed.

QWhat are HKEYS's complexity and missing-key behaviors?

HKEYS has O(N) time complexity, with N equal to the hash size. The result is an array reply, or an empty list when the key does not exist.

Follow-up: What should a client do when the result is empty? Treat it as either a missing key or a hash with no remaining fields, depending on application context.

  • HGET
  • HGETALL
  • HLEN
  • HSCAN
  • HSET

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