Skip to content

Commit 4036f61

Browse files
authored
DOC-5717: update XREADGROUP command page (#2312)
1 parent a67f352 commit 4036f61

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

content/commands/xreadgroup.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ arguments:
2525
optional: true
2626
token: BLOCK
2727
type: integer
28+
- display_text: min-idle-time
29+
name: min-idle-time
30+
optional: true
31+
token: CLAIM
32+
type: integer
2833
- display_text: noack
2934
name: noack
3035
optional: true
@@ -85,8 +90,8 @@ since: 5.0.0
8590
summary: Returns new or historical messages from a stream for a consumer in a group.
8691
Blocks until a message is available otherwise.
8792
syntax_fmt: "XREADGROUP GROUP\_group consumer [COUNT\_count] [BLOCK\_milliseconds]\n\
88-
\ [NOACK] STREAMS\_key [key ...] id [id ...]"
89-
syntax_str: "[COUNT\_count] [BLOCK\_milliseconds] [NOACK] STREAMS\_key [key ...] id\
93+
\ [CLAIM\_min-idle-time] [NOACK] STREAMS\_key [key ...] id [id ...]"
94+
syntax_str: "[COUNT\_count] [BLOCK\_milliseconds] [CLAIM\_min-idle-time] [NOACK] STREAMS\_key [key ...] id\
9095
\ [id ...]"
9196
title: XREADGROUP
9297
---
@@ -140,16 +145,47 @@ can be inspected using the [`XPENDING`]({{< relref "/commands/xpending" >}}) com
140145
The `NOACK` subcommand can be used to avoid adding the message to the PEL in
141146
cases where reliability is not a requirement and the occasional message loss
142147
is acceptable. This is equivalent to acknowledging the message when it is read.
148+
When used together with `CLAIM`, `NOACK` does not apply for retrieved pending entries.
143149

144150
The ID to specify in the **STREAMS** option when using `XREADGROUP` can
145151
be one of the following two:
146152

147-
* The special `>` ID, which means that the consumer want to receive only messages that were *never delivered to any other consumer*. It just means, give me new messages.
148-
* Any other ID, that is, 0 or any other valid ID or incomplete ID (just the millisecond time part), will have the effect of returning entries that are pending for the consumer sending the command with IDs greater than the one provided. So basically if the ID is not `>`, then the command will just let the client access its pending entries: messages delivered to it, but not yet acknowledged. Note that in this case, both `BLOCK` and `NOACK` are ignored.
153+
* When the special `>` id is specified without `CLAIM`, the consumer wants to receive only messages that were never delivered to any other consumer, hence, just new messages.
154+
* When the special `>` id is specified with `CLAIM`, the consumer wants, in addition, to receive messages that have been delivered to some consumer and have been pending for at least min-idle-time milliseconds.
155+
* Any other ID, that is, 0 or any other valid ID or incomplete ID (just the millisecond time part), will have the effect of returning entries that are pending for the consumer sending the command with IDs greater than the one provided. So basically if the ID is not `>`, then the command will just let the client access its pending entries: messages delivered to it, but not yet acknowledged. Note that in this case, `BLOCK`, `NOACK`, and `CLAIM` are ignored.
149156

150157
Like [`XREAD`]({{< relref "/commands/xread" >}}) the `XREADGROUP` command can be used in a blocking way. There
151158
are no differences in this regard.
152159

160+
## The CLAIM option
161+
162+
When `CLAIM min-idle-time` is specified, Redis will first try to claim messages which have been pending for at least min-idle-time milliseconds from the consumer group of each specified stream key. The pending messages with the highest idle time would be claimed first. Note that the `CLAIM min-idle-time` condition may become true for some pending entries during the `BLOCK milliseconds` period (if specified).
163+
164+
If there are no such messages, Redis will continue as normal (consume incoming messages).
165+
166+
`CLAIM min-idle-time` is ignored if the specified id is not `>`.
167+
168+
### Reply extension for claimed entries
169+
170+
When `CLAIM min-idle-time` is used, additional information is provided for each pending entry retrieved (similar to the reply of [`XPENDING`]({{< relref "/commands/xpending" >}})). For each claimed pending entry, the reply includes:
171+
172+
1. Entry id
173+
2. Field-value pairs
174+
3. Milliseconds since the last time this entry was delivered
175+
4. Number of times this entry was previously delivered
176+
177+
### Ordering guarantees
178+
179+
When using `CLAIM`, the following ordering guarantees apply:
180+
181+
- Idle pending entries are reported first, then incoming entries
182+
- Idle pending entries are ordered by idle time (longer first)
183+
- Incoming entries are ordered by the order they were appended to the stream (older first)
184+
185+
For example, if there are 20 idle pending entries and 200 incoming entries (in all the specified streams together):
186+
- When calling `XREADGROUP ... CLAIM ...`, you would retrieve 220 entries in the reply
187+
- When calling `XREADGROUP ... COUNT 100 ... CLAIM ...`, you would retrieve the 20 idle pending entries + 80 incoming entries in the reply
188+
153189
## What happens when a message is delivered to a consumer?
154190

155191
Two things:

0 commit comments

Comments
 (0)