ERR
RedisERRORCommonKey ErrorHIGH confidence

No such key

Production Risk

Low. The error correctly signals a failed precondition.

What this means

This error is returned by certain commands when they are required to operate on a key that does not exist. Note that many commands (like GET or DEL) do not error on a missing key, but return nil or 0 instead.

Why it happens
  1. 1The key being operated on has expired and been deleted by Redis.
  2. 2The key was never created, or was created and then deleted by another client.
  3. 3A typo in the key name being provided to the command.
How to reproduce

A client attempts to rename a key that does not exist.

trigger — this will error
trigger — this will error
DEL non_existent_key
RENAME non_existent_key new_key_name

expected output

(error) ERR no such key

Fix 1

Check for key existence before operating

WHEN Before using commands that require a key to exist

Check for key existence before operating
EXISTS mykey
# If response is 1, then proceed
# RENAME mykey my_new_key

Why this works

The `EXISTS` command allows you to verify a key is present before running a command like `RENAME` or `PERSIST` that would otherwise fail.

Fix 2

Use `RENAMENX` for safer renaming

WHEN You want to rename a key but only if the new key name doesn't already exist.

Use `RENAMENX` for safer renaming
RENAMENX old_key new_key

Why this works

While `RENAME` fails on a missing source key, `RENAMENX` provides additional safety on the destination key. Combining `EXISTS` with `RENAME` is the complete pattern.

What not to do

Rely on this error for checking key existence

Most commands don't return this error. The idiomatic way to check if a key exists is with the `EXISTS` command, and for checking a value, a `GET` command returning `nil` is standard.

Sources
Official documentation ↗

Command-specific precondition checks

Redis EXISTS command

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors