blPop, brPop 命令/方法/函数

Description

Is a blocking lPop(rPop) primitive. If at least one of the lists contains at least one element, the element will be popped from the head of the list and returned to the caller. Il all the list identified by the keys passed in arguments are empty, blPop will block during the specified timeout until an element is pushed to one of those lists. This element will be popped.

lpop命令的block版本即阻塞版本。如果LIST容器中有VAULE,将会返回ARRAY('listName''element')。如果TIMEOUT参数为空,那么如果LIST为空,blPop或者brPop将或结束调用。如果设置了timeout参数,blPop或者brPop将被挂起暂停运行TIMEOUT参数的时间,在此期间如果LIST被PUSH了元素,将在TIMEOUT时间结束后,被POP出来。


Parameters

ARRAY Array containing the keys of the lists INTEGER Timeout Or STRING Key1 STRING Key2 STRING Key3 ... STRING KeynINTEGER Timeout


Return value

ARRAY array('listName', 'element')


Example

/* Non blocking feature */

$redis->lPush('key1', 'A');

$redis->delete('key2');


$redis->blPop('key1', 'key2', 10); /* array('key1', 'A') */

/* OR */

$redis->blPop(array('key1', 'key2'), 10); /* array('key1', 'A') */


$redis->brPop('key1', 'key2', 10); /* array('key1', 'A') */

/* OR */

$redis->brPop(array('key1', 'key2'), 10); /* array('key1', 'A') */


/* Blocking feature */


/* process 1 */

$redis->delete('key1');

$redis->blPop('key1', 10);

/* blocking for 10 seconds */


/* process 2 */

$redis->lPush('key1', 'A');


/* process 1 */

/* array('key1', 'A') is returned*/