当前位置: 首页>>代码示例>>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;未经允许,请勿转载。