本文整理汇总了PHP中Predis\Client::blpop方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::blpop方法的具体用法?PHP Client::blpop怎么用?PHP Client::blpop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::blpop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get a job from queue.
* This call is blocking.
*
* @param string $key
* @param int $timeout
*
* @return string|null
*/
public function get($key, $timeout = 30)
{
if ($this->checkConnection()) {
$return = $this->predis->blpop(array(self::QUEUE_PREFIX . ':' . QueuePriority::PRIORITY_HIGH . ':' . $key, self::QUEUE_PREFIX . ':' . QueuePriority::PRIORITY_NORMAL . ':' . $key, self::QUEUE_PREFIX . ':' . QueuePriority::PRIORITY_LOW . ':' . $key), $timeout);
if (is_array($return)) {
return $return[1];
}
}
return null;
}
示例2: waitToAssignTask
/**
* @throws QueueException
* @throws \Exception
* @return Task
*/
public function waitToAssignTask()
{
$this->setActive();
// A nil multi-bulk when no element could be popped and the timeout expired.
// A two-element multi-bulk with the first element being the name of the key
// where an element was popped and the second element being the value of
// the popped element.
$redisData = $this->redisClient->blpop($this->announceListKey, 5);
//Pop timed out rather than got a task
if ($redisData === null) {
return null;
}
list(, $taskKey) = $redisData;
$serializedTask = $this->redisClient->get($this->taskListKey . $taskKey);
if (!$serializedTask) {
$data = var_export($serializedTask, true);
throw new \Exception("Failed to find expected task " . $taskKey . ". Data returned was " . $data);
}
$task = @unserialize($serializedTask);
if ($task == false) {
$this->setStatus($taskKey, TaskQueue::STATE_ERROR);
throw new QueueException("Failed to unserialize string {$serializedTask}");
}
$this->setStatus($task, TaskQueue::STATE_WORKING);
return $task;
}
示例3: receiveMessage
public function receiveMessage($queueId = null, $waitTime = 0)
{
$queueId = $this->normaliseQueueId($queueId);
if (empty($waitTime)) {
$waitTime = $this->waitTime;
}
$message = $this->predis->blpop([$queueId], $waitTime);
if (empty($message[1])) {
return null;
}
/** @var QueueMessage $queueMessage */
$queueMessage = $this->messageFactory->createMessage($message[1], $queueId);
$index = $this->receivedMessageCounter++;
$this->receivedMessages[$index] = $queueMessage;
$queueMessage->setReceiptId($index);
return $queueMessage;
}
示例4: readCommandReply
/**
* @param string $commandIdentifier
* @param int $timeout
* @return array
*/
public function readCommandReply($commandIdentifier, $timeout = null)
{
$timeout = $timeout ? $timeout : $this->timeout;
return $this->client->blpop([sprintf(self::COMMAND_RESPONSE_KEY, $commandIdentifier)], $timeout);
}