Redis WRONGTYPE Operation
Error message
WRONGTYPE Operation against a key holding the wrong kind of value
Quick summary
You tried to use a list command (e.g., LPUSH) on a key that holds a string, or a string command on a set — Redis enforces per-key types.
Why this happens
Using a list command on a key that holds a string
Using a hash command on a key that holds a set
Reusing a key name for different data types across parts of the application
Minimal example
SET mykey "hello"
LPUSH mykey "world"
# → WRONGTYPE: mykey is a string, not a listSET mykey "hello"
LPUSH mylist "world"
# Use a different key for the listThe key mykey holds a string, so LPUSH fails. Using a separate key for the list avoids the type conflict.
How to diagnose
Check the type of the key:
TYPE keyIdentify which command was used and what type it expects
Check if different parts of the application use the same key for different types
How to fix
Use the correct command for the key's data type
Delete the key and recreate it with the correct type
Use a different key name for the new data type
How to prevent
Use consistent key naming conventions that indicate the type (e.g.,
user:1:namefor strings,user:1:sessionsfor lists)Document which keys hold which types
Check the key type before operating on it if unsure
Related Resources
Related Glossary
Related Lessons
- Redis Basics
Learn about Redis data types.