NOSTREAM
RedisERRORNotableStreamsHIGH confidence

Target key does not exist or is not a stream

Production Risk

Medium — stream commands silently fail or error until the key is created; consumer groups cannot be set up.

What this means

Raised by stream commands when the target key does not exist and MKSTREAM was not specified, or when the key exists but holds a non-stream data type. Commands such as XLEN, XRANGE, XINFO STREAM, and XGROUP CREATE can produce this error.

Why it happens
  1. 1The stream key was never created (no XADD has been called on it).
  2. 2The key was deleted with DEL or expired via TTL.
  3. 3XGROUP CREATE called without MKSTREAM on a non-existent key.
  4. 4A typo in the key name.
How to reproduce

A consumer tries to inspect or read a stream that does not exist yet.

trigger — this will error
trigger — this will error
# Key does not exist
XLEN nonexistent_stream
# or
XGROUP CREATE nonexistent_stream mygroup $ 

expected output

(error) ERR The XGROUP subcommand requires the key to exist.
# For XLEN on a non-existent key it returns 0, but XINFO STREAM raises:
(error) ERR no such key

Fix 1

Use MKSTREAM to auto-create the stream

WHEN Creating a consumer group before any producers have written to the stream

Use MKSTREAM to auto-create the stream
# MKSTREAM creates the stream automatically if it does not exist
XGROUP CREATE mystream mygroup $ MKSTREAM

Why this works

The MKSTREAM flag instructs XGROUP CREATE to create an empty stream before registering the group.

Fix 2

Seed the stream with a dummy message

WHEN You need the stream to exist before consumers start

Seed the stream with a dummy message
# Write a placeholder entry so the stream exists
XADD mystream * _init true
XGROUP CREATE mystream mygroup 0

Why this works

XADD creates the stream key; XGROUP CREATE then succeeds because the key exists.

Fix 3

Check key existence before operating

WHEN The stream may legitimately not exist and the operation should be skipped

Check key existence before operating
if redis.exists("mystream"):
    info = redis.xinfo_stream("mystream")

Why this works

EXISTS returns 1 if the key is present; avoids the error when the stream is genuinely absent.

What not to do

Assume a stream exists simply because a producer should have written to it

Producers may not have run yet, or the key may have been evicted; always handle the absent-key case explicitly.

Version notes
Redis 5.0

Streams introduced; NOSTREAM / ERR no such key raised for missing stream keys.

Redis 7.0

MKSTREAM support improved across more subcommands.

Sources
Official documentation ↗

Redis Streams — key existence and MKSTREAM documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors