本文整理匯總了PHP中Redis::rPop方法的典型用法代碼示例。如果您正苦於以下問題:PHP Redis::rPop方法的具體用法?PHP Redis::rPop怎麽用?PHP Redis::rPop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Redis
的用法示例。
在下文中一共展示了Redis::rPop方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
/**
* get value from the queue
*
* @param bool $block if block when the queue is empty
* @return bool|string
*/
public function get($block = false)
{
if (!$block) {
return $this->redis->rPop($this->channel);
} else {
while (true) {
$record = $this->redis->rPop($this->channel);
if ($record === false) {
usleep(1000);
continue;
}
return $record;
}
}
}
示例2: rPop
/**
* Remove and return a value from a list
*
* @param string $key
* @return string|null
*/
public function rPop($key)
{
$result = $this->_redis->rPop($key);
if (false === $result) {
$result = null;
}
return $result;
}
示例3: testDifferentTypeHash
public function testDifferentTypeHash()
{
$key = '{hash}hash';
$dkey = '{hash}hash';
$this->redis->del($key);
$this->assertEquals(1, $this->redis->hSet($key, 'key', 'value'));
// string I/F
$this->assertEquals(FALSE, $this->redis->get($key));
$this->assertEquals(FALSE, $this->redis->getset($key, 'value2'));
$this->assertEquals(FALSE, $this->redis->append($key, 'append'));
$this->assertEquals(FALSE, $this->redis->getRange($key, 0, 8));
$this->assertEquals(array(FALSE), $this->redis->mget(array($key)));
$this->assertEquals(FALSE, $this->redis->incr($key));
$this->assertEquals(FALSE, $this->redis->incrBy($key, 1));
$this->assertEquals(FALSE, $this->redis->decr($key));
$this->assertEquals(FALSE, $this->redis->decrBy($key, 1));
// lists I/F
$this->assertEquals(FALSE, $this->redis->rPush($key, 'lvalue'));
$this->assertEquals(FALSE, $this->redis->lPush($key, 'lvalue'));
$this->assertEquals(FALSE, $this->redis->lLen($key));
$this->assertEquals(FALSE, $this->redis->lPop($key));
$this->assertEquals(FALSE, $this->redis->lrange($key, 0, -1));
$this->assertEquals(FALSE, $this->redis->lTrim($key, 0, 1));
$this->assertEquals(FALSE, $this->redis->lGet($key, 0));
$this->assertEquals(FALSE, $this->redis->lSet($key, 0, "newValue"));
$this->assertEquals(FALSE, $this->redis->lrem($key, 'lvalue', 1));
$this->assertEquals(FALSE, $this->redis->lPop($key));
$this->assertEquals(FALSE, $this->redis->rPop($key));
$this->assertEquals(FALSE, $this->redis->rPoplPush($key, $dkey . 'lkey1'));
// sets I/F
$this->assertEquals(FALSE, $this->redis->sAdd($key, 'sValue1'));
$this->assertEquals(FALSE, $this->redis->srem($key, 'sValue1'));
$this->assertEquals(FALSE, $this->redis->sPop($key));
$this->assertEquals(FALSE, $this->redis->sMove($key, $dkey . 'skey1', 'sValue1'));
$this->assertEquals(FALSE, $this->redis->scard($key));
$this->assertEquals(FALSE, $this->redis->sismember($key, 'sValue1'));
$this->assertEquals(FALSE, $this->redis->sInter($key, $dkey . 'skey2'));
$this->assertEquals(FALSE, $this->redis->sUnion($key, $dkey . 'skey4'));
$this->assertEquals(FALSE, $this->redis->sDiff($key, $dkey . 'skey7'));
$this->assertEquals(FALSE, $this->redis->sMembers($key));
$this->assertEquals(FALSE, $this->redis->sRandMember($key));
// sorted sets I/F
$this->assertEquals(FALSE, $this->redis->zAdd($key, 1, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zRem($key, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zIncrBy($key, 1, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zRank($key, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zRevRank($key, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zRange($key, 0, -1));
$this->assertEquals(FALSE, $this->redis->zRevRange($key, 0, -1));
$this->assertEquals(FALSE, $this->redis->zRangeByScore($key, 1, 2));
$this->assertEquals(FALSE, $this->redis->zCount($key, 0, -1));
$this->assertEquals(FALSE, $this->redis->zCard($key));
$this->assertEquals(FALSE, $this->redis->zScore($key, 'zValue1'));
$this->assertEquals(FALSE, $this->redis->zRemRangeByRank($key, 1, 2));
$this->assertEquals(FALSE, $this->redis->zRemRangeByScore($key, 1, 2));
}
示例4: pop
/**
* 返回隊列中的第一個元素(從底部)
* @param bool $bak 當bak為TRUE時,則會自動將隊列數據備份至kbak
* @return string $v
*/
public function pop($bak = TRUE)
{
try {
if ($bak) {
return $this->rd->rpoplpush($this->k, $this->kbak);
} else {
return $this->rd->rPop($this->k);
}
} catch (\RedisException $e) {
if ($this->reconnRedis()) {
if ($bak) {
return $this->rd->rpoplpush($this->k, $this->kbak);
} else {
return $this->rd->rPop($this->k);
}
}
}
return FALSE;
}
示例5: testrPop
public function testrPop()
{
// rpush => tail
// lpush => head
$this->redis->delete('list');
$this->redis->rPush('list', 'val');
$this->redis->rPush('list', 'val2');
$this->redis->lPush('list', 'val3');
// 'list' = [ 'val3', 'val', 'val2']
$this->assertEquals('val2', $this->redis->rPop('list'));
$this->assertEquals('val', $this->redis->rPop('list'));
$this->assertEquals('val3', $this->redis->rPop('list'));
$this->assertEquals(FALSE, $this->redis->rPop('list'));
// testing binary data
$this->redis->delete('list');
$this->assertEquals(1, $this->redis->rPush('list', gzcompress('val1')));
$this->assertEquals(2, $this->redis->rPush('list', gzcompress('val2')));
$this->assertEquals(3, $this->redis->rPush('list', gzcompress('val3')));
$this->assertEquals('val3', gzuncompress($this->redis->rPop('list')));
$this->assertEquals('val2', gzuncompress($this->redis->rPop('list')));
$this->assertEquals('val1', gzuncompress($this->redis->rPop('list')));
}
示例6: popLast
/**
* Remove and return the last element of the list.
*
* @return Bdes\Q\Item the last element of the list
*/
public function popLast()
{
return $this->redis->rPop($this->listName);
}
示例7: rpop
/**
* rpop a raw value
*
* @param string $key Cache ID
* @param string $value value
* @return mixed New value on success or FALSE on failure
*/
public function rpop($key)
{
return $this->_redis->rPop($key);
}
示例8: dequeue
/**
* 從Redis隊列中讀取一條任務
*
* @param string $queue Redis隊列名
*
* @return string JSON格式字符串
*/
public function dequeue($queue)
{
return $this->redis->rPop($queue);
}
示例9: pop
/**
* 數據出隊列
* @param string $key KEY名稱
* @param bool $left 是否從左邊開始出數據
* @return array
*/
public function pop($key, $left = true)
{
$val = $left ? parent::lPop($key) : parent::rPop($key);
return json_decode($val, true);
}
示例10: listPop
/**
* 出隊列
* @param $list1 string 隊列名
* @param $deriction int 0:數據入隊列頭(左) 1:數據入隊列尾(右) 默認為0
* @param $list2 string 第二個隊列名 默認null
* @param $timeout int timeout為0:隻獲取list1隊列的數據
* timeout>0:如果隊列list1為空 則等待timeout秒 如果還是未獲取到數據 則對list2隊列執行pop操作
*/
public static function listPop($list1, $deriction = 0, $list2 = null, $timeout = 0)
{
$redis = new \Redis();
$redis->connect(self::_HOST, self::_PORT);
$return = null;
switch ($direction) {
case 0:
if ($timeout && $list2) {
$return = $redis->blPop($list1, $list2, $timeout);
} else {
$return = $redis->lPop($list1);
}
break;
case 1:
if ($timeout && $list2) {
$return = $redis->brPop($list1, $list2, $timeout);
} else {
$return = $redis->rPop($list1);
}
break;
default:
$return = false;
break;
}
$redis->close();
$redis = null;
return $return;
}
示例11: get
/**
* get value from the queue of channel
* @param $channel
* @return mixed
*/
public function get($channel)
{
return $this->redis->rPop($channel);
}
示例12: pop
/**
* 數據出隊列(對應redis的list數據結構)
* @param string $key KEY名稱
* @param bool $left 是否從左邊開始出數據
* @return mixed
*/
public function pop($key)
{
$val = $this->redis->rPop($key);
return json_decode($val);
}
示例13: date
} else {
continue;
}
}
file_put_contents(__DIR__ . '/log/import_error_' . date('Ymd') . '.log', '[' . date('H:i:s') . ']' . "Process import sleep...\n", FILE_APPEND);
sleep(1);
}
}
if ('worker' === $_GET['step']) {
// list num
$list_id = $_GET['list'];
// save worker pid
$pidfile = __DIR__ . '/log/import_workers/LOG_LIST_' . $list_id . '.pid';
file_put_contents($pidfile, posix_getpid());
// redis cluster
$redis_cluster = new Redis();
if (!$redis_cluster->connect('192.168.4.105', 8002)) {
throw new Exception("Ubhvrcache redis(192.168.4.105:8002) unavailable.");
}
// log redis
$redis = new Redis();
$redis->connect('127.0.0.1', 5379);
// consump redis list
$key = 'LOG_LIST_' . $list_id;
while ($message = $redis->rPop($key)) {
// parse message...
// save cache...
}
// delete pid file when worker ends
unlink($pidfile);
}
示例14: rpop
public function rpop($channel)
{
return $this->client->rPop($channel);
}