Skip to content

Commit 04a0fa3

Browse files
Docs Originality Update - Batch #9 (#307)
* Docs Originality Update - Batch #9 * dragonfly prompt * adjust XACK * adjust XINFO GROUPS * adjust XINFO STREAM * adjust XLEN * adjust XRANGE * adjust XRANGE x02 * minor * adjust XPENDING * adjust XREAD * adjust XREADGROUP * adjust XREVRANGE * adjust XSETID * add back time complexity & acl categories for streams * use the same prompt for strings * adjust XTRIM --------- Co-authored-by: xf10w <[email protected]> Co-authored-by: Joe Zhou <[email protected]>
1 parent fe69fac commit 04a0fa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1194
-872
lines changed

docs/command-reference/stream/xack.md

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: Learn how to use Redis XACK to acknowledge the processing of a message from a stream by a consumer.
2+
description: Learn how to use Redis XACK to acknowledge the processing of a message from a stream by a consumer.
33
---
44

55
import PageTitle from '@site/src/components/PageTitle';
@@ -8,26 +8,102 @@ import PageTitle from '@site/src/components/PageTitle';
88

99
<PageTitle title="Redis XACK Command (Documentation) | Dragonfly" />
1010

11+
## Introduction
12+
13+
In Dragonfly, as well as in Redis and Valkey, the `XACK` command is used to acknowledge one or more messages in a stream that have been successfully processed.
14+
It is useful in stream processing systems where consumers must signal that a message has been handled, helping to manage message delivery and retention more efficiently within a consumer group.
15+
After successfully processing a message, a consumer should call `XACK` to prevent reprocessing and remove the message from the Pending Entries List (PEL).
16+
1117
## Syntax
1218

13-
XACK key group id [id ... ]
19+
```shell
20+
XACK key group id [id ...]
21+
```
1422

15-
**Time complexity:** O(1) for each message ID processed.
23+
- **Time complexity:** O(1) for each message ID processed.
24+
- **ACL categories:** @write, @stream, @fast
1625

17-
**ACL categories:** @write, @stream, @fast
26+
## Parameter Explanations
1827

19-
**XACK** command acknowledges one or more messages by removing the messages from the pending entries list (PEL) of the specified consumer stream group. A message is pending, and as such stored inside the PEL, when it was delivered to some consumer, normally as a side effect of calling XREADGROUP, or when a consumer took ownership of a message calling XCLAIM. The pending message was delivered to some consumer but the server is yet not sure it was processed at least once. So new calls to XREADGROUP to grab the messages history for a consumer (for instance using an ID of 0), will return such message. Similarly the pending message will be listed by the XPENDING command, that inspects the PEL. Once a consumer successfully processes a message, it should call **XACK** so that such message does not get processed again, and as a side effect, the PEL entry about this message is also purged, releasing memory from the Dragonfly server.
28+
- `key`: The name of the stream.
29+
- `group`: The name of the consumer group.
30+
- `id`: The ID of the message to acknowledge. Multiple IDs can be specified.
2031

32+
## Return Values
2133

22-
## Return
34+
- The command returns an integer indicating the number of messages that were successfully acknowledged.
35+
- Message IDs that are not part of the PEL (i.e., already been acknowledged) will not be considered successful acknowledgments.
36+
- If the stream or the consumer group does not exist, the command simply returns `0`.
2337

24-
[Integer reply](https://redis.io/docs/reference/protocol-spec/#integers), specifically:
38+
## Code Examples
2539

26-
The command returns the number of messages successfully acknowledged. Certain message IDs may no longer be part of the PEL (for example because they have already been acknowledged), and XACK will not count them as successfully acknowledged.
40+
### Basic Acknowledgement Example
2741

28-
## Examples
42+
Acknowledge a single message that has been processed:
2943

3044
```shell
31-
dragonfly> XACK mystream mygroup 1526569495631-0
45+
dragonfly$> XADD mystream * name Alice age 20
46+
"1609097574170-0"
47+
48+
dragonfly$> XGROUP CREATE mystream mygroup 0 MKSTREAM
49+
OK
50+
51+
dragonfly$> XREADGROUP GROUP mygroup consumer-1 COUNT 1 STREAMS mystream >
52+
1) 1) "mystream"
53+
2) 1) 1) "1609097574170-0"
54+
2) 1) "name"
55+
2) "Alice"
56+
3) "age"
57+
4) "20"
58+
59+
dragonfly$> XACK mystream mygroup "1609097574170-0"
3260
(integer) 1
3361
```
62+
63+
### Acknowledging Multiple Messages
64+
65+
Acknowledge multiple messages after processing:
66+
67+
```shell
68+
dragonfly$> XADD mystream * name Bob age 25
69+
"1609097574171-0"
70+
71+
dragonfly$> XADD mystream * name Charlie age 30
72+
"1609097574172-0"
73+
74+
# The consumer reads the 2 new messages.
75+
dragonfly$> XREADGROUP GROUP mygroup consumer-1 COUNT 2 STREAMS mystream >
76+
# ...
77+
78+
# Acknowledge the 2 messages for the consumer group.
79+
dragonfly$> XACK mystream mygroup "1609097574171-0" "1609097574172-0"
80+
(integer) 2
81+
```
82+
83+
### Handling Non-existent IDs
84+
85+
Acknowledge attempt on a non-existent message ID:
86+
87+
```shell
88+
dragonfly$> XACK mystream mygroup "1609097574173-0"
89+
(integer) 0 # No acknowledgment since the ID does not exist.
90+
```
91+
92+
## Best Practices
93+
94+
- Use `XACK` to signal message processing completion to avoid reprocessing and free up resources.
95+
- Implement proper error handling to manage message IDs that may no longer exist or are not yet acknowledged.
96+
97+
## Common Mistakes
98+
99+
- Attempting to acknowledge messages using IDs that were never read by the group.
100+
101+
## FAQs
102+
103+
### What happens if the message ID is not found?
104+
105+
If the message ID does not exist in the pending entries list of the consumer group, `XACK` returns `0`.
106+
107+
### Can `XACK` be used for automatic acknowledgement?
108+
109+
No, `XACK` requires explicit calls to acknowledge messages after successful processing by consumers.

docs/command-reference/stream/xadd.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Streams are data structures that enable storing and processing ordered logs of e
1919
XADD key [<MAXLEN | MINID> [~ | =] threshold] <* | id> field value [field value ...]
2020
```
2121

22+
- **Time complexity:** O(1) when adding a new entry, O(N) when trimming where N being the number of entries evicted.
23+
- **ACL categories:** @write, @stream, @fast
24+
2225
## Parameter Explanations
2326

2427
- `key`: The key of the stream where the entry will be appended.

docs/command-reference/stream/xautoclaim.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ which is particularly useful in scenarios where message processing needs to be r
2121
XAUTOCLAIM key group consumer min-idle-time start [COUNT count] [JUSTID]
2222
```
2323

24+
- **Time complexity:** O(1) if `COUNT` is small.
25+
- **ACL categories:** @write, @stream, @fast
26+
2427
## Parameter Explanations
2528

2629
- `key`: The key of the stream.

docs/command-reference/stream/xclaim.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ XCLAIM key group consumer min-idle-time id [id ...] [IDLE ms] [TIME ms-unix-time
2020
[RETRYCOUNT count] [FORCE] [JUSTID]
2121
```
2222

23+
- **Time complexity:** O(log N) with N being the number of messages in the pending entries list (PEL) of the consumer group.
24+
- **ACL categories:** @write, @stream, @fast
25+
2326
## Parameter Explanations
2427

2528
- `key`: The key of the stream.

docs/command-reference/stream/xdel.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ This command is particularly useful for managing data in stream-like structures
1919
XDEL key ID [ID ...]
2020
```
2121

22+
- **Time complexity:** O(1) for each single item to delete in the stream, regardless of the stream size.
23+
- **ACL categories:** @write, @stream, @fast
24+
2225
## Parameter Explanations
2326

2427
- `key`: The key of the stream from which entries are to be deleted.

docs/command-reference/stream/xgroup-create.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ This command is essential for managing distributed message processing systems wh
2020
XGROUP CREATE key group <id | $> [MKSTREAM]
2121
```
2222

23+
- **Time complexity:** O(1)
24+
- **ACL categories:** @write, @stream, @slow
25+
2326
## Parameter Explanations
2427

2528
- `key`: The key name of the stream.

docs/command-reference/stream/xgroup-createconsumer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ This command is part of the streams data type which facilitates managing consume
1919
XGROUP CREATECONSUMER key group consumer
2020
```
2121

22+
- **Time complexity:** O(1)
23+
- **ACL categories:** @write, @stream, @slow
24+
2225
## Parameter Explanations
2326

2427
- `key`: The key of the stream for which the consumer is being created.

docs/command-reference/stream/xgroup-delconsumer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Therefore, be sure to claim or acknowledge any pending messages before removing
2121
XGROUP DELCONSUMER key group consumer
2222
```
2323

24+
- **Time complexity:** O(1)
25+
- **ACL categories:** @write, @stream, @slow
26+
2427
## Parameter Explanations
2528

2629
- `key`: The key of the stream.

docs/command-reference/stream/xgroup-destroy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Use this command only when absolutely necessary.**
2121
XGROUP DESTROY key group
2222
```
2323

24+
- **Time complexity:** O(N) where N is the number of entries in the group's pending entries list (PEL).
25+
- **ACL categories:** @write, @stream, @slow
26+
2427
## Parameter Explanations
2528

2629
- `key`: The name of the stream from which the consumer group will be deleted.

docs/command-reference/stream/xgroup-setid.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ This command is beneficial when you need to reprocess messages or adjust a consu
1919
XGROUP SETID key group <id | $>
2020
```
2121

22+
- **Time complexity:** O(1)
23+
- **ACL categories:** @write, @stream, @slow
24+
2225
## Parameter Explanations
2326

2427
- `key`: The key of the stream.

0 commit comments

Comments
 (0)