Skip to content

Consumer Groups

A consumer group lets multiple workers (consumers) read from the same stream, with each entry delivered to only ONE consumer in the group. Redis tracks which entries have been delivered but not yet acknowledged. This enables at-least-once processing.

127.0.0.1:6379> XADD jobs * type "email" to "[email protected]"
"1700000000000-0"
127.0.0.1:6379> XADD jobs * type "sms" to "+6681234567"
"1700000000001-0"
127.0.0.1:6379> XGROUP CREATE jobs workers $ MKSTREAM
OK

$ means “start from the latest entry” — only new messages added after the group is created will be delivered. Use 0 to read from the beginning of the stream. MKSTREAM creates the stream automatically if it does not exist yet.

127.0.0.1:6379> XADD jobs * type "email" to "[email protected]"
"1700000000002-0"
127.0.0.1:6379> XREADGROUP GROUP workers consumer-1 COUNT 1 STREAMS jobs >
1) 1) "jobs"
2) 1) 1) "1700000000002-0"
2) 1) "type"
2) "email"
3) "to"

The special ID > means “give me new undelivered entries”. Once delivered, the entry is placed in the Pending Entries List (PEL) for consumer-1 until it is explicitly acknowledged.

127.0.0.1:6379> XACK jobs workers 1700000000002-0
(integer) 1

Once acknowledged, the entry is removed from the PEL. Only call XACK after your worker has successfully processed the message — acknowledging too early risks data loss if the worker crashes mid-processing.

XPENDING — inspecting unacknowledged entries

Section titled “XPENDING — inspecting unacknowledged entries”
127.0.0.1:6379> XPENDING jobs workers - + 10
1) 1) "1700000000002-0"
2) "consumer-1"
3) (integer) 4321
4) (integer) 1

Each row shows: the entry ID, the consumer holding it, how long it has been idle in milliseconds, and how many times it has been delivered. This is your primary tool for detecting stuck or slow consumers.

XADD jobs * type "email" to "[email protected]"
XADD jobs * type "sms" to "+6681234567"
XGROUP CREATE jobs workers 0 MKSTREAM
XREADGROUP GROUP workers consumer-1 COUNT 10 STREAMS jobs >
XACK jobs workers 1700000000000-0
XPENDING jobs workers - + 10
What does `XREADGROUP GROUP g consumer STREAMS s >` mean?
What happens to a stream entry after XACK is called?
What does XPENDING show?
In `XGROUP CREATE jobs workers 0 MKSTREAM`, what does `0` mean?