• 请不要在回答技术问题时复制粘贴 AI 生成的内容
crimeshaper
V2EX  ›  程序员

关于 redis stream 问题

  •  
  •   crimeshaper · Jan 21, 2020 · 2295 views
    This topic created in 2320 days ago, the information mentioned may be changed or developed.

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

    3 replies    2020-01-22 14:50:22 +08:00
    crimeshaper
        1
    crimeshaper  
    OP
       Jan 21, 2020
    用了 block 就默认使用了 count 1,无解了。
    ql562482472
        2
    ql562482472  
       Jan 22, 2020
    没有意义呀 你可以在业务代码中缓存一下 到 50 再返回
    stcheng
        3
    stcheng  
       Jan 22, 2020
    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 中加入缓存逻辑。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   915 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 19:49 · PVG 03:49 · LAX 12:49 · JFK 15:49
    ♥ Do have faith in what you're doing.