如何在redispy中指定“>”

2024-10-03 00:21:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在redis stream documentation中看到这个,上面写着:

It is time to try reading something using the consumer group:

> XREADGROUP GROUP mygroup Alice COUNT 1 STREAMS mystream >
1) 1) "mystream"
   2) 1) 1) 1526569495631-0
         2) 1) "message"
            2) "apple"

XREADGROUP replies are just like XREAD replies. Note however the GROUP provided above, it states that I want to read from the stream using the consumer group mygroup and I'm the consumer Alice. Every time a consumer performs an operation with a consumer group, it must specify its name uniquely identifying this consumer inside the group.

There is another very important detail in the command line above, after the mandatory STREAMS option the ID requested for the key mystream is the special ID >. This special ID is only valid in the context of consumer groups, and it means: messages never delivered to other consumers so far.

我试图在redis py中指定“>;”参数。你知道吗

当我查看文档here时,我在流中没有看到任何参数可以让我这样做。具体来说,我正在尝试:

>>> r.xreadgroup(mygroupname,myconsumer,{mystream : ">"},1)
[] # oh no, empty. WHY?!
# 
# even though
>>> r.xread({mystream: '1561950326849-0'}, count=1)
[[b'stuff-returned-successfully.]]

我错过了什么?为什么我不能指定一个“>;”来表示未看到的消息?你知道吗


Tags: thetoredisidstreamtimeconsumeris
1条回答
网友
1楼 · 发布于 2024-10-03 00:21:01

在这个问题上,你错误地认为你有/看不见/信息。该命令应该可以工作,但如果您已经看到所有消息一次,则不会工作。你知道吗

试试看

# make sure you have not seen anything in your stream by resetting last seen to 0
>>> r.xgroup_setid(mystream,mygroupname,0) # RESET ALL

现在

r.xreadgroup(mygroupname,myconsumer,{mystream : ">"},1)

很好用。你知道吗

相关问题 更多 >