在开始使用消息分组之前,我们必须手动创建分组才行,以下是几个和 Stream 分组有关的命令,我们先来学习一下它的使用。
消息分组命令
创建消费者群组
127.0.0.1:6379> xgroup create mq group1 0-0
OK
相关语法:
xgroup create stream-key group-key ID
其中:
- mq 为 Stream 的 key;
- group1 为分组的名称;
- 0-0 表示从第一条消息开始读取。
如果要从当前最后一条消息向后读取,使用 $
即可,命令如下:
127.0.0.1:6379> xgroup create mq group2 $
OK
读取消息
127.0.0.1:6379> xreadgroup group group1 c1 count 1 streams mq >
1) 1) "mq"2) 1) 1) "1580959593553-0"2) 1) "name"2) "redis"3) "age"4) "10"
相关语法:
xreadgroup group group-key consumer-key streams stream-key
其中: