# WRONGTYPE: The key holds a different data type

> The command expects one Redis data type and the key holds another: a list command on a string key, for example.

Source: https://sqlly.app/errors/redis/wrongtype
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error prefix: `WRONGTYPE`
- Category: Data types and commands

Error message:

```text
WRONGTYPE Operation against a key holding the wrong kind of value
```

## What it means

WRONGTYPE means the key exists but holds a different data type than the command needs. Redis keys are not schema-bound: strings, lists, sets, sorted sets, hashes and streams share one namespace, and the type is a property of the value, not of the key name. LPUSH on a key that holds a string fails exactly like this.

It is the Redis equivalent of a schema mismatch, and it usually starts as a naming collision: two parts of the application using one key name for two purposes, or an older writer that created the key as a string before a feature switched it to a hash. The investigation starts with TYPE, which tells you what you are actually holding.

## Common causes

- Two code paths use the same key name for different types, so whichever creates the key first wins.
- A migration or refactor changed the type a feature uses, and keys from the previous format are still there.
- A deserializer or ORM hands the command the wrong field name, pointing at a string key next to the collection key.

## Commands and the types they require

| | |
| --- | --- |
| GET, SET, INCR, APPEND | string |
| LPUSH, RPUSH, LRANGE, LPOP | list |
| HSET, HGET, HGETALL | hash |
| SADD, SMEMBERS, SINTER | set |
| ZADD, ZRANGE, ZRANK | sorted set |
| XADD, XREAD, XGROUP | stream |

## How to fix it

1. Check the actual type and encoding before changing any code:

   ```sql
   TYPE user:1000
   OBJECT ENCODING user:1000
   ```
2. Rename one side of the collision so each purpose has its own key:

   ```sql
   RENAME user:1000 user:1000:profile-backup
   ```
3. Once nothing else writes to the old key, delete or rebuild it with the right commands:

   ```sql
   DEL user:1000
   HSET user:1000 name alice plan pro
   ```

## Reproduce it safely

```sql
redis-cli SET user:1000 alice
redis-cli LPUSH user:1000 tasks
# (error) WRONGTYPE Operation against a key holding the wrong kind of value
redis-cli TYPE user:1000
# string
```

## How SQLly helps

SQLly prints the full WRONGTYPE line in the results pane, and TYPE and OBJECT ENCODING run from the same editor, so the mismatch is a two-command check rather than a code hunt.

## Questions

### How do I see a key's type?

TYPE key prints it: string, list, set, zset, hash, stream, bitmap or vectorset. OBJECT ENCODING adds the internal encoding, which explains behavior differences inside one type.

### Why is Redis strict about this?

Commands are typed per data structure. Silently coercing types would make every writer depend on the order in which readers and writers happened to run.

### Can one key hold two types?

No. A key has exactly one value with one type. Put the second structure under a different key.

## Related errors

- [`Conversion Error`](https://sqlly.app/errors/duckdb/conversion-could-not-convert): DuckDB: The value cannot be cast to the target type
- [`42804`](https://sqlly.app/errors/postgresql/42804): PostgreSQL: datatype mismatch
- [`SQLITE_MISMATCH`](https://sqlly.app/errors/sqlite/sqlite-mismatch): SQLite: datatype mismatch

The code and message text are from the [Redis documentation and source code](https://redis.io/docs/latest/).
