Redis "WRONGTYPE Operation against a key holding the wrong kind of value" in CI
A command for one data type ran against a key that already holds another type. For Redis Streams this happens when a key used for XADD/XREADGROUP was previously set as a string or list, often by leftover state from an earlier test.
What this error means
A stream command fails with "WRONGTYPE Operation against a key holding the wrong kind of value" while the same logic works on a clean key.
WRONGTYPE Operation against a key holding the wrong kind of valueCommon causes
The key already holds a different type
A prior SET or RPUSH made the key a string or list, so a stream command on it is a type mismatch.
Leftover state across CI runs reused the key
A persisted Redis kept the key from an earlier run with the wrong type, so the stream command collides with it.
How to fix it
Use a dedicated key and verify its type
Check the type and use distinct key namespaces for streams.
redis-cli TYPE events # should print: stream
redis-cli DEL events # clear a stale wrong-typed keyStart from a clean Redis per run
Use an ephemeral Redis service container so no stale key of the wrong type survives.
- Run Redis as a fresh service container each CI run.
- Avoid reusing the same key name for different data types.
- FLUSHDB at test setup if a shared instance is unavoidable.
How to prevent it
- Keep stream keys in a namespace separate from other types.
- Use an ephemeral Redis per CI run to avoid stale keys.
- Verify key type before issuing type-specific commands.