예제 #1
0
파일: RedisQuery.php 프로젝트: aoyel/pinst
 public static function pop($key)
 {
     $redis = self::instance();
     if ($redis) {
         self::$redis->lPop($key);
     }
 }
예제 #2
0
 /**
  * Block until the first message arrives
  *
  * @param int $key
  * @param mixed $message
  * @return bool
  */
 public function receive($key, &$message)
 {
     while ($this->client->lSize($key) <= 0) {
         usleep(self::WAIT_USLEEP);
     }
     $message = $this->client->lPop($key);
     return true;
 }
예제 #3
0
 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
0
 public function testlistTrim()
 {
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val');
     $this->redis->lPush('list', 'val2');
     $this->redis->lPush('list', 'val3');
     $this->redis->listTrim('list', 0, 0);
     $this->assertEquals(1, $this->redis->lSize('list'));
     $this->assertEquals('val', $this->redis->lPop('list'));
 }
예제 #5
0
 public function statusCheck()
 {
     $redis = new Redis();
     $settings = $this->__getSetSettings();
     $redis->connect($settings['redis_host'], $settings['redis_port']);
     $redis->select($settings['redis_database']);
     $redis->rPush($settings['redis_namespace'] . ':command', 'status');
     sleep(1);
     $response = trim($redis->lPop($settings['redis_namespace'] . ':status'));
     return json_decode($response, true);
 }
예제 #6
0
파일: TestRedis.php 프로젝트: 0/phpredis
 public function testlistTrim()
 {
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val');
     $this->redis->lPush('list', 'val2');
     $this->redis->lPush('list', 'val3');
     $this->redis->lPush('list', 'val4');
     $this->assertEquals(TRUE, $this->redis->listTrim('list', 0, 2));
     $this->assertEquals(3, $this->redis->lSize('list'));
     $this->redis->listTrim('list', 0, 0);
     $this->assertEquals(1, $this->redis->lSize('list'));
     $this->assertEquals('val4', $this->redis->lPop('list'));
     $this->assertEquals(TRUE, $this->redis->listTrim('list', 10, 10000));
     $this->assertEquals(TRUE, $this->redis->listTrim('list', 10000, 10));
     // test invalid type
     $this->redis->set('list', 'not a list...');
     $this->assertEquals(FALSE, $this->redis->listTrim('list', 0, 2));
 }
예제 #7
0
 /**
  * Get message from queue
  *
  * @return \Apple\ApnPush\Notification\MessageInterface|null
  *
  * @throws \RuntimeException
  */
 public function getMessage()
 {
     static $useSleep = false;
     if (!$this->listKey) {
         throw new \RuntimeException('Can\'t get message. Undefined list key.');
     }
     if (!$this->redis) {
         throw new \RuntimeException('Can\'t get message. Not found redis instance.');
     }
     if ($useSleep && $this->sleepTimeout) {
         usleep($this->sleepTimeout);
     }
     if ($data = $this->redis->lPop($this->listKey)) {
         $useSleep = false;
         return unserialize($data);
     } else {
         $useSleep = true;
     }
     return null;
 }
예제 #8
0
 function subscribe_run()
 {
     $this->load->config('redis');
     $redis_config = $this->config->item('redis');
     $redis = new Redis();
     $redis->pconnect($redis_config['write']['hostname'], $redis_config['write']['port']);
     while (true) {
         try {
             $data = $redis->lPop(Config::$subscribe_queue_redis_key);
             if ($data) {
                 $redis->incr("dy_lzl_success");
                 $path = __DIR__;
                 $app_path = FCPATH;
                 $cmd = "/bin/sh " . $path . "/push.sh '{$app_path}' '{$data}' ";
                 $redis->set("cmd", $cmd);
                 @system($cmd, $return);
             }
         } catch (Exception $e) {
             $redis->incr("dy_lzl_error");
         }
     }
 }
예제 #9
0
 /**
  * @inheritdoc
  */
 public function pop()
 {
     return $this->redis->lPop($this->name);
 }
예제 #10
0
파일: Redis.php 프로젝트: BD-ES/Q
 /**
  * Remove and return the First element of the list.
  *
  * @return Bdes\Q\Item the last element of the list
  */
 public function popFirst()
 {
     return $this->redis->lPop($this->listName);
 }
예제 #11
0
파일: Wk_Redis.php 프로젝트: telander/waka
 /**
  * @param string $key
  * @return string
  */
 public function lPop($key)
 {
     $this->_useCnt++;
     return $this->_wrapBoolReturn(function () use($key) {
         return parent::lPop($key);
     });
 }
예제 #12
0
$redis->connect('127.0.0.1');
if ($argv[1] == "start") {
    if ($redis->exists('get_price_pids')) {
        echo "get price daemon may already start.";
        exit;
    }
    echo "start\n\r";
    foreach ($market_list as $market) {
        echo "start market : {$market} \n\r";
        system("/usr/local/bin/php {$path}/get_price.php {$market}");
    }
    exit;
}
if ($argv[1] == "stop") {
    echo "stop\n\r";
    $pid = $redis->lPop('get_price_pids');
    while (!empty($pid)) {
        system("kill -9 {$pid}");
        echo "stop pid : {$pid} \n\r";
        $pid = $redis->lPop('get_price_pids');
    }
    exit;
}
echo "restart\n\r";
$pid = $redis->lPop('get_price_pids');
while (!empty($pid)) {
    system("kill -9 {$pid}");
    echo "stop pid : {$pid} \n\r";
    $pid = $redis->lPop('get_price_pids');
}
foreach ($market_list as $market) {
예제 #13
0
파일: CxRedis.php 프로젝트: cloklo/CxWoole
 /**
  * 数据出队列
  * @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);
 }
예제 #14
0
 /**
  * 出队列
  * @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;
 }