python - 如何在redis-py中指定 ">"

标签 python redis

我正在 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.]]

我错过了什么?为什么我不能指定“>”来表示未看到的消息?

最佳答案

您在这个问题中错误地假设您有/unseen/消息。该命令应该有效,但如果您已经看过所有消息一次,则不会。

尝试

# 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)

工作正常。

关于python - 如何在redis-py中指定 ">",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56829731/

相关文章:

python - 从 -0.1 - 0.2 到 0-255 缩放一个 numpy 数组

python - 测试 python 函数的非确定性行为

python - 在存在 NaN 的情况下将 pandas 列拆分为新列

Python 请求 : How to set optional and non-optional parameters at the same time?

session - 使用 Redis 存储 session 有多安全?

ruby-on-rails - 为什么我的 Angular 应用程序不向我的 Entangle rails Controller 发送参数?

redis - 如何删除redis中的整个流?

python - HTML 表格——在标题中放置链接进行排序? (无 JavaScript)

.net - Redis缓存.Net客户端

集群模式下的 Redis 流