关于 redis stream 问题

2020-01-21 14:46:14 +08:00
 crimeshaper

各位大佬,xread 和 xreadgroup block 阻塞后,一有新值就会立即返回,count 参数没用,就失效了。例如: XREAD BLOCK 5000 COUNT 100 STREAMS mystream $ 我想阻塞到凑够 count 数,比如 100 条后再返回,怎么解决,求各位不吝赐教啊。

1613 次点击
所在节点    程序员
3 条回复
crimeshaper
2020-01-21 19:01:15 +08:00
用了 block 就默认使用了 count 1,无解了。
ql562482472
2020-01-22 13:28:18 +08:00
没有意义呀 你可以在业务代码中缓存一下 到 50 再返回
stcheng
2020-01-22 14:50:22 +08:00
redis 本身不支持这样使用,根据官方文档:
“When the BLOCK command is passed, but there is data to return at least in one of the streams passed, the command is executed synchronously exactly like if the BLOCK option would be missing.”
只要有 data,block 立刻就会被 resume。

一方面考虑这个“达到 100 条再返回”的需求是否合理,另外一方面考虑如果有这个需求的话,同意在 wrapper 中加入缓存逻辑。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/639675

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX