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

Redis · Module

EXISTS

EXISTS determines whether one or more Redis keys exist and returns the number found. It can check multiple keys in one command.

Since
1.0.0

How it works

EXISTS examines each supplied key and returns how many of those keys are present. Supplying the same existing key more than once counts that key once for every occurrence, and checking N keys has O(N) complexity.

Syntax

EXISTS key [key ...]

Parameters

NameTypeDescription
key [key ...]key namesOne or more keys to check for existence. A repeated key is counted once per occurrence.

Returns

Integer reply: the number of keys that exist among the specified arguments.

Key points

  • Use EXISTS to test whether a key or a group of keys is present.
  • The integer reply is the count of supplied keys currently found.
  • A repeated existing key contributes separately for every appearance in the argument list.
  • Runtime grows linearly with the number of key names passed.
  • The command syntax requires at least one key and permits additional keys.

Common mistakes

  • Repeated key names are not deduplicated: an existing key contributes to the returned count on every occurrence.
  • Multi-key checks can behave differently in a Redis Cluster, so consult the cluster guidance before relying on them across slots.

Example: Check key existence

SET key1 "Hello"
EXISTS key1
EXISTS nosuchkey
SET key2 "World"
EXISTS key1 key2 nosuchkey

Creates two keys, then checks one or several keys and returns the count that currently exist.

When to use it

Cache-presence checks

Before reading or updating cached data, determine whether a requested key is present.

Batch existence tests

Check several candidate keys and use the returned count for conditional logic.

Post-operation verification

Verify that deletion or another lifecycle operation removed the expected keys.

Interview questions

QWhat does EXISTS return?

EXISTS takes one or more key names and returns an integer equal to the number that exist. For a single key, that result is effectively 1 or 0.

Follow-up: What is the complexity for checking several keys? It is O(N), where N is the number of keys supplied.

QHow does EXISTS handle multiple keys?

The command accepts key [key ...], so a call can test multiple keys at once. Its result is the count of existing keys among the arguments.

Follow-up: What happens if one existing key is repeated? Each occurrence is counted, so repeating it can increase the result.

QWhat operational caveat applies in Redis Cluster?

EXISTS is a read-only keyspace command that determines whether one or more keys exist. In clustered deployments, multi-key behavior varies, so cluster-specific multi-key rules must be considered.

Follow-up: Why can a multi-key request be problematic in a cluster? Keys may not be handled like a single local-key operation across cluster slots.

  • SET
  • DEL
  • HEXISTS

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