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

Redis · Module

HEXISTS

Checks whether a field exists in a Redis hash. It returns 1 for an existing field and 0 when the field or hash key is absent.

Since
2.0.0

How it works

HEXISTS tests whether one field is present in the hash stored at a key. It returns 1 when the field exists and 0 when either the field is absent or the key does not exist; using a non-hash key produces a wrong-type error.

Syntax

HEXISTS key field

Parameters

NameTypeDescription
keykeyThe name of the key that holds the hash.
fieldfieldThe field to check for existence.

Returns

Integer reply: 1 if the hash contains the field; 0 if it does not contain the field or the key does not exist.

Key points

  • Tests one named field in the hash associated with the supplied key.
  • The key argument identifies the Redis hash to inspect.
  • The field argument is the hash-field name whose presence is tested.
  • Redis returns integer 0 when the field is absent.
  • Redis returns integer 1 when the field exists.
  • The command has a fixed two-argument signature: a hash key followed by a field.

Common mistakes

  • A missing key produces the same 0 result as a hash that lacks the requested field.
  • The command's documented result is an integer reply, not the field's stored value.

Example: Check hash-field existence

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

Creates a hash field, then checks two fields; Redis returns 1 for the existing name and 0 for the absent email.

When to use it

Presence checks

Validate whether an optional attribute has been stored before reading or updating it.

Conditional hash handling

Avoid treating a missing hash field as an existing value in application logic.

Record inspection

Test membership of feature flags, user attributes, or other hash-backed records.

Interview questions

QWhat does HEXISTS do?

HEXISTS takes a hash key and one field name. It returns 1 when that field exists in the hash, otherwise 0, including when the key is missing.

Follow-up: What is its time complexity? It is O(1), so checking one field does not require scanning the hash.

QWhat arguments does HEXISTS require?

The command accepts exactly two arguments after the command name: the key containing the hash and the field to test. Its syntax is HEXISTS key field.

Follow-up: How would you check several fields? Issue separate HEXISTS commands or use a pipelined client operation; HEXISTS itself checks one field per invocation.

QHow should the return value be interpreted?

A result of 0 is ambiguous: the hash may not contain the field, or the key may not exist. A result of 1 means the field is present in the hash.

Follow-up: What happens if the key stores a string, list, or another non-hash type? Redis reports a wrong-type error rather than returning 0 or 1.

  • HSET
  • HGET
  • HDEL
  • HKEYS
  • HLEN

Source: HEXISTS | Docs. Checked 2026-10-16.