Categories About Us Contact Us Become a Member

How to fix the Redis WRONGTYPE error

This means you ran a command meant for one data type against a key that holds a different type. Using the right command for the key's actual type resolves it. Jump to your situation below or work through the methods in order.

By Neeraj Singh ~6 min Updated Jun 2026 89% found this helpful
Error message
WRONGTYPE Operation against a key holding the wrong kind of value.
Summary

The Redis WRONGTYPE Operation against a key holding the wrong kind of value error means a command was run against a key whose data type does not match the command. Redis keys each hold a specific type, string, hash, list, set, sorted set, stream, and commands are type-specific: running HSET on a key that holds a plain string, or LPUSH on a hash, triggers WRONGTYPE. It usually comes from a key-name collision (two parts of the code using the same key for different structures) or a wrong assumption about a key's type. The fix is to check the actual type with TYPE key, then either use the correct command for that type or use a different key name so each structure has its own key. Namespacing keys by type prevents collisions.

What this error means

Every Redis key has one data type, fixed when the key is created. Commands belong to a type too, so HSET expects a hash and LPUSH expects a list. WRONGTYPE means the command and the key's type disagree: the key exists, but it is not the kind the command operates on.

The usual root cause is a naming clash, two code paths reusing the same key for different structures, or code assuming a type the key does not actually have. Checking the type tells you the truth, and either using the right command or giving each structure a distinct, namespaced key resolves it.

Common causes

A command was used against a key of a different type.
Two code paths share a key name for different structures.
A wrong assumption about a key's data type.
A key was overwritten as a different type elsewhere.
A migration left a key as an unexpected type.
Expert insight

“WRONGTYPE is Redis saying that key is not the shape you think it is. The key exists, but you fired a hash command at a string, or a list command at a set. Almost always it is a key-name collision, two bits of code grabbing the same key for different data. So I run TYPE on the key to see what it actually is, then either use the right command or, better, namespace the keys so a session string and a user hash never share a name. Clear naming makes this error vanish.”

How to fix it

Method 1

Check the key's actual type

1Find out what the key really holds:
TYPE mykey
2Then use the command set that matches, hash commands for a hash, list commands for a list, and so on.
3This usually reveals a mismatch.
Method 2

Use distinct, namespaced key names

1Give each structure its own key, for example user:100:profile (hash) and user:100:sessions (list).
2This prevents two structures sharing one key.
3Update the code that collided.
Method 3

Recreate the key as the right type

1If a key is the wrong type for what you need, delete it and recreate it correctly:
DEL mykey
2Then write it with the intended type's commands.
3Migrate any data you need first.
Method 4

Guard against type assumptions in code

1Where types can vary, check TYPE before operating, or handle the WRONGTYPE error.
2This avoids crashes on unexpected data.
3Add tests for the key shapes you expect.

WRONGTYPE means the command does not match the key's data type, usually a key-name collision. Run TYPE key to see what it actually holds, then use the matching command or give each structure a distinct, namespaced key name. Recreate a key with DEL if it must change type.

Frequently asked questions

What does the Redis WRONGTYPE error mean?
It means you ran a command against a key whose data type does not match. Redis commands are type-specific, so running a hash command on a string key, for example, triggers WRONGTYPE.
How do I fix it?
Check the key's real type with TYPE key, then use the command set that matches it. If two structures clashed on one key name, give each its own namespaced key.
Why does this usually happen?
Most often a key-name collision: two parts of the code use the same key for different data structures. It can also be a wrong assumption about what type a key holds.
How do I see a key's type?
Run TYPE key. It returns the data type, such as string, hash, list, set, zset or stream, so you know which commands are valid for it.
Can I change a key's type?
Not in place. Delete the key with DEL and recreate it with the intended type's commands, migrating any data you need first. A key's type is fixed once set.
How do I prevent it?
Namespace keys clearly by purpose, for example user:100:profile versus user:100:sessions, so different structures never share a name, and check TYPE in code where the type can vary.

Still not working?

If WRONGTYPE appears intermittently, two services are likely writing the same key as different types under load; logging which client and command set the key, or using a key-naming convention enforced in code review, isolates the offender. You can also submit your error to us for a tailored fix.

Was this fix helpful? Thanks for your feedback!