當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Redis::blPop方法代碼示例

本文整理匯總了PHP中Redis::blPop方法的典型用法代碼示例。如果您正苦於以下問題:PHP Redis::blPop方法的具體用法?PHP Redis::blPop怎麽用?PHP Redis::blPop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Redis的用法示例。


在下文中一共展示了Redis::blPop方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: pop

 /**
  * Does a Redis BLPOP on the queue, and blocks until a job is available.
  *
  * @return Job
  */
 function pop()
 {
     $response = $this->redis->blPop($this->key, 10);
     if ($response) {
         list($list, $serializedJob) = $response;
         $job = unserialize($serializedJob);
         return $job;
     }
 }
開發者ID:chh,項目名稱:kue,代碼行數:14,代碼來源:RedisQueue.php

示例2: getOutput

 /**
  * @param string $type
  * @param InputMessageIdentifier $identifier
  * @return OutputMessage
  */
 public function getOutput($type, InputMessageIdentifier $identifier)
 {
     $messageId = $identifier->getId();
     $data = $this->redis->hGet($this->getMessageResultKey($type), $messageId);
     if (empty($data)) {
         return null;
     }
     do {
         $resultReady = $this->redis->blPop($this->getMessageResultReadyKey($type, $messageId), 1);
     } while (empty($resultReady));
     $data = $this->redis->hGet($this->getMessageResultKey($type), $messageId);
     $this->redis->hDel($this->getMessageResultKey($type), $messageId);
     return new OutputMessage($data);
 }
開發者ID:parallel-php,項目名稱:parallel-task,代碼行數:19,代碼來源:RedisQueue.php

示例3: testblockingPop

 public function testblockingPop()
 {
     // non blocking blPop, brPop
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val1');
     $this->redis->lPush('list', 'val2');
     $this->assertTrue($this->redis->blPop(array('list'), 2) === array('list', 'val2'));
     $this->assertTrue($this->redis->blPop(array('list'), 2) === array('list', 'val1'));
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val1');
     $this->redis->lPush('list', 'val2');
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val1'));
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val2'));
     // blocking blpop, brpop
     $this->redis->delete('list');
     $this->assertTrue($this->redis->blPop(array('list'), 1) === array());
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array());
     // TODO: fix this broken test.
     //		$this->redis->delete('list');
     //		$params = array(
     //			0 => array("pipe", "r"),
     //			1 => array("pipe", "w"),
     //			2 => array("file", "/dev/null", "w")
     //		);
     //		if(function_exists('proc_open')) {
     //			$env = array('PHPREDIS_key' =>'list', 'PHPREDIS_value' => 'value');
     //			$process = proc_open('php', $params, $pipes, '/tmp', $env);
     //
     //			if (is_resource($process)) {
     //				fwrite($pipes[0],  '<?php
     //	sleep(2);
     //	$r = new Redis;
     //	$r->connect("'.self::HOST.'", '.self::PORT.');
     //	if("'.addslashes(self::AUTH).'") {
     //		$r->auth("'.addslashes(self::AUTH).'");
     //	}
     //	$r->lPush($_ENV["PHPREDIS_key"], $_ENV["PHPREDIS_value"]);
     //	?' . '>');
     //
     //				fclose($pipes[0]);
     //				fclose($pipes[1]);
     //				$re = proc_close($process);
     //
     //				$this->assertTrue($this->redis->blPop(array('list'), 5) === array("list", "value"));
     //			}
     //		}
 }
開發者ID:stonegithubs,項目名稱:phpredis,代碼行數:47,代碼來源:TestRedis.php

示例4: tryLock

 protected function tryLock()
 {
     $this->redis->watch('lock');
     $result = $this->redis->blPop(array('lock'), static::LOCK_TIMEOUT);
     return !empty($result);
 }
開發者ID:rybakit,項目名稱:taskqueue,代碼行數:6,代碼來源:RedisQueue.php

示例5: getResult

 public function getResult($taskId)
 {
     $serializedTaskResult = $this->redis->hGet($this->getTaskResultKey(), $taskId);
     if (empty($serializedTaskResult)) {
         return null;
     }
     do {
         $resultReady = $this->redis->blPop($this->getTaskResultReadyKey($taskId), 1);
     } while (empty($resultReady));
     $serializedTaskResult = $this->redis->hGet($this->getTaskResultKey(), $taskId);
     $taskResult = unserialize($serializedTaskResult);
     $this->redis->hDel($this->getTaskResultKey(), $taskId);
     if ($taskResult instanceof TaskException) {
         throw $taskResult;
     }
     return $taskResult;
 }
開發者ID:drealecs,項目名稱:thread-worker,代碼行數:17,代碼來源:RedisQueue.php

示例6: testblockingPop

 public function testblockingPop()
 {
     // non blocking blPop, brPop
     $this->redis->del('list');
     $this->redis->lPush('list', 'val1');
     $this->redis->lPush('list', 'val2');
     $this->assertTrue($this->redis->blPop(array('list'), 2) === array('list', 'val2'));
     $this->assertTrue($this->redis->blPop(array('list'), 2) === array('list', 'val1'));
     $this->redis->del('list');
     $this->redis->lPush('list', 'val1');
     $this->redis->lPush('list', 'val2');
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val1'));
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val2'));
     // blocking blpop, brpop
     $this->redis->del('list');
     $this->assertTrue($this->redis->blPop(array('list'), 1) === array());
     $this->assertTrue($this->redis->brPop(array('list'), 1) === array());
 }
開發者ID:Jerry-Shaw,項目名稱:phpredis,代碼行數:18,代碼來源:RedisTest.php

示例7: listen

 /**
  * @inheritDoc
  */
 public function listen($timeout)
 {
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->redis->blPop($this->name, $timeout);
 }
開發者ID:s1lent1um,項目名稱:traktor,代碼行數:8,代碼來源:RedisQueue.php

示例8: die

    die('CLI access only');
}
require 'helper.php';
require 'class/minecraftforum.php';
require 'class/ipbxmlrpc.php';
require 'config/application.php';
$redis = new Redis();
$redis->connect(REDIS_IP, REDIS_PORT);
$redis->auth(REDIS_AUTH);
$minecraftforum = new Minecraftforum();
$minecraftforum->authenticate(MCF_USER, MCF_PASS);
$user_updates = array();
echo 'Authenticated with IPB' . "\n";
while (true) {
    // listen for new users
    $user = $redis->blPop("users", 5);
    if (!$user) {
        continue;
    }
    $user_data = json_decode($user[1]);
    if (@isset($user_updates[$user_data->member_id]) && @$user_updates[$user_data->member_id] > time() - 120) {
        echo "user {$user_data->member_id} skipping, already updated in the last 120 seconds (2 mins) :)\n";
        continue;
    }
    $update = $minecraftforum->edit_member($user_data->member_id, array("field_16" => $user_data->time), $user_data->view_key);
    if ($update) {
        $log_string = "user {$user_data->member_id} updated (time: {$user_data->time})" . "\n";
        $user_updates[$user_data->member_id] = time();
    } else {
        $log_string = "user {$user_data->member_id} could not be updated, invalid key :( (time: {$user_data->time})" . "\n";
    }
開發者ID:notcitricsquid,項目名稱:rules,代碼行數:31,代碼來源:redis.php

示例9: 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;
 }
開發者ID:skyshow,項目名稱:ticket,代碼行數:36,代碼來源:MyRedis.class.php


注:本文中的Redis::blPop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。