Skip to content
Latchkey

redis-cli XADD and XREAD: Redis Streams

redis-cli XADD <key> * field value appends an entry to a Redis Stream and XREAD or XREADGROUP reads it back, giving Redis a durable log for messaging tests.

Redis Streams turn Redis into a lightweight message log with consumer groups. This page covers the stream commands specifically; general redis-cli usage (INFO, cluster, config) is covered separately.

What it does

A Redis Stream is an append-only log. XADD appends an entry (with * to auto-generate the id); XLEN returns the length; XREAD reads entries after an id; XREADGROUP reads within a consumer group created by XGROUP CREATE, and XACK acknowledges them. This is the messaging-oriented subset of redis-cli.

Common usage

Terminal
redis-cli XADD orders '*' id 1 status new
redis-cli XLEN orders
# read everything from the start
redis-cli XREAD COUNT 10 STREAMS orders 0
# consumer group flow
redis-cli XGROUP CREATE orders g1 0
redis-cli XREADGROUP GROUP g1 c1 COUNT 1 STREAMS orders '>'

Options

CommandWhat it does
XADD <key> * <f> <v>Append an entry with an auto id
XLEN <key>Number of entries in the stream
XREAD COUNT <n> STREAMS <key> <id>Read entries after an id (0 = all)
XGROUP CREATE <key> <group> <id>Create a consumer group
XREADGROUP GROUP <g> <c> STREAMS <key> >Read new entries for a group
XACK <key> <group> <id>Acknowledge a processed entry

In CI

Use * as the id in XADD so Redis assigns a monotonic id and you avoid collisions across test runs. For consumer-group tests, create the group with XGROUP CREATE before reading, and use the special > id in XREADGROUP to fetch only never-delivered messages.

Common errors in CI

"WRONGTYPE Operation against a key holding the wrong kind of value" means the key already exists as a string or list, not a stream; use a fresh key or FLUSHDB in setup. "BUSYGROUP Consumer Group name already exists" from XGROUP CREATE is harmless on a retried run; ignore it or add MKSTREAM. "Could not connect to Redis at ...: Connection refused" means the server is not up on 6379.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →