【问题标题】:Redis - Reliable queue pattern with multiple pops in one requestRedis - 一个请求中具有多个弹出的可靠队列模式
【发布时间】:2018-09-02 18:50:32
【问题描述】:

我使用 BRPOPLPUSH 实现了Redis's reliable queue pattern,因为我想避免轮询。

但是,这会导致对每个项目的网络请求。我怎样才能增加它,以便工作人员一次 BRPOPLPUSH 的多个条目?

【问题讨论】:

  • 这个问题对我来说没有编译 - 一次弹出多个条目是什么意思?
  • @ItamarHaber 类似 BRPOPLPUSH src dest count
  • 所以等到至少有count 弹出?最多?确切地?如果存在并发阻塞客户端,这有什么意义?

标签: redis


【解决方案1】:

虽然BRPOPLPUSH 正在阻止RPOPLSPUSHdo not support transactions 的版本,但由于LUA 执行性质,您可以t handle multiple entries. Also you cant 将LUA 用于此目的:在LUA 脚本完成之前,服务器将被阻止新请求。

您可以使用应用程序端逻辑来解决您需要的队列模式。伪语言

func MyBRPOPLPUSH(source, dest, maxItems = 1, timeOutTime = 0) { 
   items = []
   timeOut = time() + timeOutTime
   while ((timeOut > 0 && time() < timeOut) || items.count < maxItems) {
      item = redis.RPOPLSPUSH(source, dest)
      if (item == nil) {
         sleep(someTimeHere);
         continue;
      }
      items.add(item)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 2018-08-12
    • 2017-12-28
    • 2015-06-25
    • 1970-01-01
    • 2016-01-02
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多