本文整理汇总了PHP中Predis\Client::lpop方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::lpop方法的具体用法?PHP Client::lpop怎么用?PHP Client::lpop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::lpop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subscribe
/**
* Show the asynchronous client logs in the main process logger (console)
*
* @return string|null
*
* @throws \RuntimeException
*/
public static function subscribe()
{
if (!isset(self::$redisClient)) {
throw new \RuntimeException('Redis client has not been initialised');
}
while (null != ($log = self::$redisClient->lpop(ConfigurationLoader::get('client.async.redis.key') . '.client.logs'))) {
list($level, $message) = explode('|', $log);
self::$logger->addRecord($level, $message);
}
}
示例2: consume
/**
* @param string $queue
*/
public function consume($queue)
{
$value = $this->client->lpop($queue);
if ($value === null) {
return;
}
$decoded = json_decode($value, true);
$command = call_user_func($this->resolver, $decoded['command']);
$command->withOptions($decoded['options'])->execute();
}
示例3: getAssociation
/**
* Read association from Redis. If no handle given
* and multiple associations found, returns latest issued
*/
function getAssociation($server_url, $handle = null)
{
// simple case: handle given
if ($handle !== null) {
return $this->getAssociationFromServer($this->associationKey($server_url, $handle));
}
// no handle given, receiving the latest issued
$serverKey = $this->associationServerKey($server_url);
$lastKey = $this->redis->lpop($serverKey);
if (!$lastKey) {
return null;
}
// get association, return null if failed
return $this->getAssociationFromServer($lastKey);
}
示例4: run
protected function run($urlMethod, $runMethod)
{
$this->getSize();
// 从redis拿出数据,并定义url,随后开始爬行逻辑
while (static::$count < $this->endCounts) {
if ($len = $this->redis->llen('usernames')) {
for ($i = 0; $i < $len; $i++) {
Crawler::$urlMethod($this->redis->lpop('usernames'));
if (!$this->{$runMethod}()) {
continue;
}
}
static::$count++;
} else {
$this->getUsernames(static::$count * $this->size);
}
}
}
示例5: pop
/**
* @inheritdoc
*/
public function pop($queue)
{
foreach ([':delayed', ':reserved'] as $type) {
$options = ['cas' => true, 'watch' => $queue . $type];
$this->redis->transaction($options, function (MultiExec $transaction) use($queue, $type) {
$data = $this->redis->zrangebyscore($queue . $type, '-inf', $time = time());
if (!empty($data)) {
$transaction->zremrangebyscore($queue . $type, '-inf', $time);
$transaction->rpush($queue, $data);
}
});
}
$data = $this->redis->lpop($queue);
if ($data === null) {
return false;
}
$this->redis->zadd($queue . ':reserved', [$data => time() + $this->expire]);
$data = Json::decode($data);
return ['id' => $data['id'], 'body' => $data['body'], 'queue' => $queue];
}
示例6: flushQueue
/**
* {@inheritdoc}
*/
public function flushQueue(\Swift_Transport $transport, &$failedRecipients = null)
{
if (!$this->redis->llen($this->key)) {
return 0;
}
if (!$transport->isStarted()) {
$transport->start();
}
$failedRecipients = (array) $failedRecipients;
$count = 0;
$time = time();
while ($message = unserialize($this->redis->lpop($this->key))) {
$count += $transport->send($message, $failedRecipients);
if ($this->getMessageLimit() && $count >= $this->getMessageLimit()) {
break;
}
if ($this->getTimeLimit() && time() - $time >= $this->getTimeLimit()) {
break;
}
}
return $count;
}
示例7: getCounters
/**
* @param int $max
* @return array
*/
public function getCounters($max = 30)
{
$counters = [];
$number = 0;
while (true) {
$redisData = $this->redisClient->lpop($this->getCounterKey());
if (!$redisData) {
break;
}
$counter = unserialize($redisData);
$counters[] = $counter;
$number++;
if ($number >= $max) {
break;
}
}
return $counters;
}