diff --git a/中间件/redis/redis.md b/中间件/redis/redis.md index 5941edc..c8972ed 100644 --- a/中间件/redis/redis.md +++ b/中间件/redis/redis.md @@ -108,6 +108,7 @@ - [checking the message content](#checking-the-message-content) - [XCLAIM](#xclaim) - [JUSTID option](#justid-option) + - [Automatic claiming](#automatic-claiming) # redis @@ -1924,3 +1925,31 @@ XCLAIM的使用示例如下所示: `claiming并非一定要位于consumer自身的进程中,其也可以被实现在独立的进程中`: - `可以使用独立的进程来扫描pending messages list,并且将pending messages分配给明显处于活跃状态的consumers` +##### Automatic claiming +在redis 6.2版本中,添加了`XAUTOCLAIM`命令,实现了上一章节中描述的claiming process。`XPENDING`和`XCLAIM`命令为各种不同的recovery机制提供了基础。而`XAUTOCLAIM`命令优化了通用的`claiming process`,令`claiming process`由redis来进行管理,为大多的recovery提供简单的解决方案。 + +`XAUTOCLAIM`命令会识别idle messages并且转移message的ownership给指定consumer。`XAUTOCLAIM`命令的形式如下所示: +```redis-cli +XAUTOCLAIM [COUNT count] [JUSTID] +``` + +故而,可以通过如下方式来使用automatic claiming: +```redis-cli +> XAUTOCLAIM race:italy italy_riders Alice 60000 0-0 COUNT 1 +1) "0-0" +2) 1) 1) "1692632662819-0" + 2) 1) "rider" + 2) "Sam-Bodden" +``` +和`XCLAIM`类似,其返回结果为`an array of the claimed messsages`。但是,其还会返回一个stream ID(`在上述示例中为0-0`)。返回的stream ID可以用于对pending entries进行迭代。该stream ID为一个cursor,可以将其用作下次XAUTOCLAIM调用的`start`: +```redis-cli +> XAUTOCLAIM race:italy italy_riders Lora 60000 (1692632662819-0 COUNT 1 +1) "1692632662819-0" +2) 1) 1) "1692632647899-0" + 2) 1) "rider" + 2) "Royce" +``` + +当`XAUTOCLAIM`返回“0-0”作为cursor时,代表其到达了`end of the consumer group pending entries list`。其并不代表没有新的idle pending messages,可以重新从begining of the stream来调用`XAUTOCLAIM`。 + +