WRONGTYPE
RedisERRORNotableType ErrorHIGH confidence

Operation against a key holding the wrong kind of value

What this means

This error occurs when a client attempts to execute a command on a key that holds a value of an incompatible data type. Redis is strictly typed, and commands are specific to data structures.

Why it happens
  1. 1Using a string command (e.g., GET) on a key that holds a List.
  2. 2Using a Hash command (e.g., HGET) on a key that holds a Set.
  3. 3Application logic not validating or tracking key types before operating on them.
How to reproduce

A client runs GET on a key that stores a Redis List instead of a String.

trigger — this will error
trigger — this will error
SET mykey "hello"
DEL mykey
RPUSH mykey "a" "b" "c"
GET mykey

expected output

(error) WRONGTYPE Operation against a key holding the wrong kind of value

Fix 1

Check the key type before operating on it

WHEN When you are unsure what type a key holds

Check the key type before operating on it
TYPE mykey
# returns: list
# then use list commands
LRANGE mykey 0 -1

Why this works

The TYPE command returns the data type of the value stored at a key, allowing you to choose the correct command.

Fix 2

Delete and recreate the key with the correct type

WHEN When the key was created with the wrong type by mistake

Delete and recreate the key with the correct type
DEL mykey
SET mykey "correct string value"

Why this works

Deleting the key removes the existing value, then SET creates a new String value.

What not to do

Ignore the WRONGTYPE error and retry with a different command

Blindly retrying corrupts application logic; investigate why the wrong type exists.

Sources
Official documentation ↗

Redis RESP protocol — error replies

Redis Data Types

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

← All Redis errors