V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
crimeshaper
V2EX  ›  程序员

关于 redis stream 问题

  •  
  •   crimeshaper · 2020-01-21 14:46:14 +08:00 · 1596 次点击
    这是一个创建于 1528 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    3 条回复    2020-01-22 14:50:22 +08:00
    crimeshaper
        1
    crimeshaper  
    OP
       2020-01-21 19:01:15 +08:00
    用了 block 就默认使用了 count 1,无解了。
    ql562482472
        2
    ql562482472  
       2020-01-22 13:28:18 +08:00
    没有意义呀 你可以在业务代码中缓存一下 到 50 再返回
    stcheng
        3
    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 中加入缓存逻辑。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4053 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:18 · PVG 18:18 · LAX 03:18 · JFK 06:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.