Skip to content

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

✗ Broken code
SET mykey "hello"
LPUSH mykey "world"
# → WRONGTYPE: mykey is a string, not a list
✓ Fixed code
SET mykey "hello"
LPUSH mylist "world"
# Use a different key for the list

The 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 key

  • Identify 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:name for strings, user:1:sessions for lists)

  • Document which keys hold which types

  • Check the key type before operating on it if unsure

Related Resources

Related Glossary

Related Lessons

← Back to language