Redis 列表(list) 命令

当列表为空时,brpoplpush 命令将阻塞连接,直到等待超时,或有另一个客户端对 该列表 执行。超时参数 timeout 接受一个以秒为单位的数字作为值。超时参数设为 0 表示永久阻塞 。

语法:

redis 127.0.0.1:6379> brpoplpush list1 another_list timeout 

    可用版本

    >=2.2.0.

    返回值

    存储在 key 或 nil 的元素的值

    返回值类型

    字符串

    示例:redis brpoplpush

    127.0.0.1:6379> rpush mycolor1 r g b
    (integer) 3
    127.0.0.1:6379> rpush mycolor2 y o p
    (integer) 3
    127.0.0.1:6379> brpoplpush  mycolor1 mycolor2 100
    "b"
    127.0.0.1:6379> brpoplpush  mycolor1 mycolor2 100
    "g"
    127.0.0.1:6379> brpoplpush  mycolor1 mycolor2 100
    "r"
    127.0.0.1:6379> brpoplpush  mycolor1 mycolor2 100
    
    (nil)
    (100.06s) 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    以上示例将阻止客户端 100 秒执行任何命令。如果指定的键列表中有任何数据,则它将弹出数据并将其推送到另一个列表中,否则在 100 秒后返回 nil 值。

    (nil)
    (100.06s) 
    • 1