本文内容为 http://www.redis.io/commands/brpop 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
BRPOP key [key ...] timeout

命令 BLPOP 是一条阻塞式(Blocking)列表弹出(Pop)原语(Primitive)

BRPOP is a blocking list pop primitive.

它是命令 RPOP 的带阻塞功能版本,因为当其发现所有给定列表都不能弹出元素时,将会阻塞当前连接(Connection)

It is the blocking version of RPOP because it blocks the connection when there are no elements to pop from any of the given lists.

一个元素将从第一个非空列表的尾部(Tail)弹出,且按命令中所给定的顺序对所有键进行检测。

An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given.

查询命令 BLPOP 以获得更多详细语义,事实上命令 BRPOP 与命令 BLPOP 基本相同,仅有的差别就是从列表尾部弹出元素,而不是从头部弹出。

See the BLPOP documentation for the exact semantics, since BRPOP is identical to BLPOP with the only difference being that it pops elements from the tail of a list instead of popping from the head.
  • 返回一组响应,根据不同情况明确地分为以下结果:

    • 当没有元素可以被弹出,且设置的过期时间到期时,返回 nil
    • 如果返回的结果包含两个部份,第一个部位为从中弹出一个元素的键的名字(Name),而第二部份为所弹出元素的值(Value)
    Array reply: specifically:
    • A nil multi-bulk when no element could be popped and the timeout expired.
    • A two-element multi-bulk with the first element being the name of the key where an element was popped and the second element being the value of the popped element.
  • redis> DEL list1 list2
    (integer) 0
    redis> RPUSH list1 a b c
    (integer) 3
    redis> BRPOP list1 list2 0
    1) "list1"
    2) "c"
  • 版本支持

    2.0.0+

    时间复杂度(Time complexity)

    O(1)