Skip to content
Latchkey

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.

Terminal
WRONGTYPE Operation against a key holding the wrong kind of value

Common 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.

Terminal
redis-cli TYPE events   # should print: stream
redis-cli DEL events    # clear a stale wrong-typed key

Start from a clean Redis per run

Use an ephemeral Redis service container so no stale key of the wrong type survives.

  1. Run Redis as a fresh service container each CI run.
  2. Avoid reusing the same key name for different data types.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →