Upstash Documentation

XREADGROUP

Read as consumer group.
3 min read

Use XREADGROUP to read entries from a stream as a member of a consumer group, so that each entry goes to one consumer and Redis keeps track of what has not been acknowledged.

After STREAMS, all keys come first and then one ID per key. The special ID > delivers entries that have never been delivered to the group and records them as pending for this consumer. Any other ID re-reads that consumer's own pending entries instead, starting after the given ID, which is how a consumer resumes after a restart: read from 0 first to finish old work, then switch to >.

The consumer is created on first use. COUNT limits the batch size and BLOCK <milliseconds> waits for new entries rather than returning empty, with 0 waiting indefinitely. NOACK skips the pending entries list entirely, trading the delivery guarantee for speed.

Entries stay pending until acknowledged with XACK. That is what makes recovery possible: work left behind by a crashed consumer is visible in XPENDING and can be taken over with XAUTOCLAIM.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
GROUP <group> <consumer>YesNoConsumer group to read from, and the consumer within it that claims the entries.
COUNT <count>NoNoMaximum number of entries to return per stream.
BLOCK <milliseconds>NoNoMilliseconds to block waiting for new entries; 0 blocks indefinitely.
NOACKNoNoDo not add delivered entries to the pending list.
STREAMS <key> [<key> ...] <ID> [<ID> ...]YesNoStreams to read. List every key first, then one ID per key in the same order.

Important points#

  • A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout.
  • After STREAMS, provide all keys first and then exactly one ID for each key, in the same order.
  • COUNT and BLOCK each require a value. Giving either without one returns a wrong number of arguments error.

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
RESP2Null bulk string or null array or Flat array of alternating keys and values
RESP3Null or Map
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