BUSYKEY
RedisERRORNotableKey ErrorHIGH confidence

Target key name already exists

Production Risk

Low. The server is correctly preventing accidental data loss.

What this means

This error occurs with commands like MIGRATE or RESTORE when the target key already exists on the destination and the command was not instructed to replace it. It's a safety mechanism to prevent accidental data overwrites.

Why it happens
  1. 1Attempting to `RESTORE` a key onto a destination where that key name is already in use.
  2. 2Running a `MIGRATE` command for a key that has already been successfully migrated but not deleted from the source.
  3. 3A race condition where two processes try to create the same key on the destination instance.
How to reproduce

A client tries to restore a key 'mykey' but 'mykey' already exists on the server.

trigger — this will error
trigger — this will error
SET mykey "initial value"
# DUMP mykey produces some payload, e.g., "..."
RESTORE mykey 0 "...payload..."

expected output

(error) BUSYKEY Target key name already exists.

Fix 1

Use the `REPLACE` modifier

WHEN When you intentionally want to overwrite the destination key

Use the `REPLACE` modifier
RESTORE mykey 0 "...payload..." REPLACE

Why this works

The `REPLACE` option explicitly tells the `RESTORE` or `MIGRATE` command that it is allowed to delete the existing key at the destination before proceeding.

Fix 2

Delete the key from the destination before running the command

WHEN When you want to ensure a clean slate before the operation

Delete the key from the destination before running the command
DEL mykey
RESTORE mykey 0 "...payload..."

Why this works

By manually deleting the key, you ensure the precondition for the command (the key not existing) is met.

What not to do

Always use `REPLACE` without checking

Blindly using `REPLACE` can lead to unintentional data loss if the key on the destination had important data that was different from what you are restoring.

Version notes
Pre-6.2.0

Older versions of `RESTORE` would not return this error and would simply fail or overwrite, depending on the exact version. BUSYKEY provides clearer semantics.

Sources
Official documentation ↗

Key creation and replacement logic for restore/migrate.

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

← All Redis errors