From 110b653c2d5e429f36bb05d08291cc6e077c3976 Mon Sep 17 00:00:00 2001 From: asahi Date: Thu, 11 Sep 2025 17:29:24 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E9=98=85=E8=AF=BBredis=20stream?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 中间件/redis/redis.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/中间件/redis/redis.md b/中间件/redis/redis.md index 0c7347f..266b49d 100644 --- a/中间件/redis/redis.md +++ b/中间件/redis/redis.md @@ -100,6 +100,7 @@ - [XREAD with STREAMS option](#xread-with-streams-option) - [XREAD with BLOCK argument](#xread-with-block-argument) - [Consumer groups](#consumer-groups) + - [Creating a consumer group](#creating-a-consumer-group) # redis @@ -1655,3 +1656,14 @@ consumer group包含如下的基本命令: - XACK - XACKDEL +##### Creating a consumer group +可以通过如下方式来为stream创建一个consumer group: +```redis-cli +> XGROUP CREATE race:france france_riders $ +OK +``` +在上述示例中,在通过command创建consumer group时,以`$`的形式指定了一个`ID`。该ID是必要的,该ID将作为consumer group创建时的`last message ID`,在第一个consumer连接时,会根据向consumer传递`大于last message ID的消息`。 +- 当将last message ID指定为`$`时,只有`new messages arriving in the stream from now on`会被传递给consumer group中的consumer instances。由于`$`代表`current greatest ID in the stream`,指定`$`代表`consuming only new messages` +- 如果在此处指定了`0`,那么consumer group将会消费`all the messages in the stream history` +- 此处,也可以指定其他的`valid ID`,`consumer group will start delivering messages that are greater than the ID you specify` +