Upstash Documentation

XGROUP

Manage consumer groups.
2 min read

Use XGROUP to manage the consumer groups of a stream.

CREATE registers a group and sets the position it starts reading from: 0 replays the whole stream from the beginning, while $ delivers only entries added after the group was created. MKSTREAM creates the stream too when it does not exist yet, which avoids an error on a group created before the first producer runs. SETID moves that position afterwards, which is how a group is rewound for a replay or fast-forwarded past a backlog.

CREATECONSUMER and DELCONSUMER add and remove consumers explicitly; consumers are otherwise created on first read. Deleting a consumer returns how many pending entries went away with it, and those entries are then no longer pending for anyone, so hand them over with XCLAIM or XAUTOCLAIM first if the work still matters.

DESTROY removes a group along with all of its pending state, while leaving the stream and its entries untouched.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
subcommandYesNoConsumer-group operation shown in the syntax block.
keyYesNoStream key.
groupYesNoConsumer-group name.
consumerSome formsNoConsumer name for CREATECONSUMER or DELCONSUMER.
id | $Some formsNoStarting or replacement last-delivered ID; $ means the stream's latest ID.
MKSTREAMNoNoCreate an empty stream when CREATE targets a missing key.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Simple string OK for CREATE and SETID; Integer for CREATECONSUMER, DELCONSUMER, and DESTROY
RESP3Simple string OK for CREATE and SETID; Integer for CREATECONSUMER, DELCONSUMER, and DESTROY
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs