redis brpop java用法_redis.clients.jedis.Jedis

BLPOP (and BRPOP) is a blocking list pop primitive. You can see this commands as blocking

versions of LPOP and RPOP able to block if the specified keys don't exist or contain empty

lists.

The following is a description of the exact semantic. We describe BLPOP but the two commands

are identical, the only difference is that BLPOP pops the element from the left (head) of the

list, and BRPOP pops from the right (tail).

Non blocking behavior

When BLPOP is called, if at least one of the specified keys contain a non empty list, an

element is popped from the head of the list and returned to the caller together with the name

of the key (BLPOP returns a two elements array, the first element is the key, the second the

popped value).

Keys are scanned from left to right, so for instance if you issue BLPOP list1 list2 list3 0

against a dataset where list1 does not exist but list2 and list3 contain non empty lists, BLPOP

guarantees to return an element from the list stored at list2 (since it is the first non empty

list starting from the left).

Blocking behavior

If none of the specified keys exist or contain non empty lists, BLPOP blocks until some other

client performs a LPUSH or an RPUSH operation against one of the lists.

Once new data is present on one of the lists, the client finally returns with the name of the

key unblocking it and the popped value.

When blocking, if a non-zero timeout is specified, the client will unblock returning a nil

special value if the specified amount of seconds passed without a push operation against at

least one of the specified keys.

The timeout argument is interpreted as an integer value. A timeout of zero means instead to

block forever.

Multiple clients blocking for the same keys

Multiple clients can block for the same key. They are put into a queue, so the first to be

served will be the one that started to wait earlier, in a first-blpopping first-served fashion.

blocking POP inside a MULTI/EXEC transaction

BLPOP and BRPOP can be used with pipelining (sending multiple commands and reading the replies

in batch), but it does not make sense to use BLPOP or BRPOP inside a MULTI/EXEC block (a Redis

transaction).

The behavior of BLPOP inside MULTI/EXEC when the list is empty is to return a multi-bulk nil

reply, exactly what happens when the timeout is reached. If you like science fiction, think at

it like if inside MULTI/EXEC the time will flow at infinite speed :)

Time complexity: O(1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值