예제 #1
0
파일: RedisQuery.php 프로젝트: aoyel/pinst
 public static function push($key, $value)
 {
     $redis = self::instance();
     if ($redis) {
         self::$redis->lPush($key, $value);
     }
 }
예제 #2
0
 /**
  * put value into the queue
  *
  * @param $value
  * @return bool
  */
 public function put($value)
 {
     if ($this->redis->lPush($this->channel, $value) !== false) {
         return true;
     }
     return false;
 }
예제 #3
0
파일: Client.php 프로젝트: aladin1394/CM
 /**
  * Prepend a value to a list
  *
  * @param string $key
  * @param string $value
  * @throws CM_Exception_Invalid
  */
 public function lPush($key, $value)
 {
     $length = $this->_redis->lPush($key, $value);
     if (false === $length) {
         throw new CM_Exception_Invalid('Cannot push to list `' . $key . '`.');
     }
 }
예제 #4
0
 /**
  * 将批量数据加入队列开头
  * @注意:当加入的数据量较大,比如超过10KB时,建议使用pipeline方式
  * @注意:当提交的数据条数较多时,$pipeline为FALSE效率更高
  * @param array $arrValues array('v1','v2') 按照数组的顺序,第一个元素将首先被加入队列,最后一个元素将最后加入队列
  * @param bool $pipeline 默认为FALSE。当为TRUE时,通过PIPELINE的模式提交,为FALSE时,通过原生的方式提交。
  * @return long 成功返回TRUE(可能是0),失败时返回FALSE
  */
 public function pushMulti($arrValues, $pipeline = FALSE)
 {
     if ($pipeline) {
         if (!$this->rd->isConnected()) {
             if (!$this->reconnRedis()) {
                 return FALSE;
             }
         }
         $this->rd->multi(\Redis::PIPELINE);
         foreach ($arrValues as $v) {
             $this->rd->lPush($this->k, $v);
         }
         $re = $this->rd->exec();
         return TRUE;
     } else {
         array_unshift($arrValues, $this->k);
         try {
             return call_user_func_array(array($this->rd, 'lPush'), $arrValues);
         } catch (\RedisException $e) {
             if ($this->reconnRedis()) {
                 return call_user_func_array(array($this->rd, 'lPush'), $arrValues);
             }
         }
     }
     return FALSE;
 }
예제 #5
0
 /**
  * @inheritdoc
  */
 public function abort($messageId)
 {
     $this->checkClientConnection();
     $numberOfRemoved = $this->client->lRem("queue:{$this->name}:processing", $messageId, 0);
     if ($numberOfRemoved === 1) {
         $this->client->lPush("queue:{$this->name}:failed", $messageId);
     }
 }
예제 #6
0
 public function testlGet()
 {
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val');
     $this->redis->lPush('list', 'val2');
     $this->redis->lPush('list', 'val3');
     $this->assertEquals('val', $this->redis->lGet('list', 0));
     $this->assertEquals('val2', $this->redis->lGet('list', 1));
     $this->assertEquals('val3', $this->redis->lGet('list', 2));
     $this->redis->lPush('list', 'val4');
     $this->assertEquals('val4', $this->redis->lGet('list', 3));
 }
예제 #7
0
/**
 * Queue a task to be run by Celery.
 *
 * @param task Celery task name.
 * @param args (Optional) array of arguments.
 * @param kwargs (Optional) hash of keyword arguments.
 */
function queue_task($task, $args = null, $kwargs = null)
{
    // assemble Celery-ready messages
    $body = array("id" => uniqid(CELERY_ID_PREFIX), "task" => $task);
    if (!empty($args)) {
        $body["args"] = $args;
    }
    if (!empty($kwargs)) {
        $body["kwargs"] = $kwargs;
    }
    $envelope = array("content-encoding" => "utf-8", "content-type" => "application/json", "body" => base64_encode(json_encode($body)), "properties" => array("body_encoding" => "base64", "delivery_tag" => uniqid(CELERY_ID_PREFIX), "delivery_mode" => 2, "delivery_info" => array("exchange" => CELERY_REDIS_KEY, "routing_key" => CELERY_REDIS_KEY, "priority" => 0)));
    $redis = new Redis();
    $redis->connect(REDIS_HOST);
    $redis->lPush(CELERY_REDIS_KEY, json_encode($envelope));
    $redis->close();
}
예제 #8
0
 /**
  * @param string $type
  * @param InputMessageIdentifier $identifier
  * @param OutputMessage $outputMessage
  */
 public function putOutput($type, InputMessageIdentifier $identifier, OutputMessage $outputMessage)
 {
     $messageId = $identifier->getId();
     $captureResult = 'MessageNotFinished' === $this->redis->hGet($this->getMessageResultKey($type), $messageId);
     $this->redis->multi();
     $this->redis->lRem($this->getMessageRunKey($type), $messageId, 0);
     $this->redis->hDel($this->getMessageStartTimeKey($type), $messageId);
     $this->redis->lRem($this->getMessageQueueKey($type), $messageId, 0);
     $this->redis->hDel($this->getMessageQueueTimeKey($type), $messageId);
     $this->redis->hDel($this->getMessageKey($type), $messageId);
     if ($captureResult) {
         $data = $outputMessage->getData();
         $this->redis->hSet($this->getMessageResultKey($type), $messageId, $data);
         $this->redis->lPush($this->getMessageResultReadyKey($type, $messageId), 'true');
     }
     $this->redis->exec();
 }
예제 #9
0
 public function end($task)
 {
     $taskId = $task->getId();
     $captureResult = 'TaskNotFinished' === $this->redis->hGet($this->getTaskResultKey(), $taskId);
     $this->redis->multi();
     $this->redis->lRem($this->getTaskRunKey(), $taskId, 0);
     $this->redis->hDel($this->getTaskStartTimeKey(), $taskId);
     $this->redis->lRem($this->getTaskQueueKey(), $taskId, 0);
     $this->redis->hDel($this->getTaskQueueTimeKey(), $taskId);
     $this->redis->hDel($this->getTaskKey(), $taskId);
     if ($captureResult) {
         $taskResult = $task->getResult();
         $serializedTaskResult = serialize($taskResult);
         $this->redis->hSet($this->getTaskResultKey(), $taskId, $serializedTaskResult);
         $this->redis->lPush($this->getTaskResultReadyKey($taskId), 'true');
     }
     $this->redis->exec();
 }
예제 #10
0
 public function testlGetRange()
 {
     $this->redis->delete('list');
     $this->redis->lPush('list', 'val');
     $this->redis->lPush('list', 'val2');
     $this->redis->lPush('list', 'val3');
     // pos :   0     1     2
     // pos :  -3    -2    -1
     // list: [val3, val2, val]
     $this->assertEquals($this->redis->lGetRange('list', 0, 0), array('val3'));
     $this->assertEquals($this->redis->lGetRange('list', 0, 1), array('val3', 'val2'));
     $this->assertEquals($this->redis->lGetRange('list', 0, 2), array('val3', 'val2', 'val'));
     $this->assertEquals($this->redis->lGetRange('list', 0, 3), array('val3', 'val2', 'val'));
     $this->assertEquals($this->redis->lGetRange('list', 0, -1), array('val3', 'val2', 'val'));
     $this->assertEquals($this->redis->lGetRange('list', 0, -2), array('val3', 'val2'));
     $this->assertEquals($this->redis->lGetRange('list', -2, -1), array('val2', 'val'));
     $this->redis->delete('list');
     $this->assertEquals($this->redis->lGetRange('list', 0, -1), array());
 }
예제 #11
0
 /**
  * 入队列
  * @param $list string 队列名
  * @param $value mixed 入队元素值
  * @param $deriction int 0:数据入队列头(左) 1:数据入队列尾(右) 默认为0
  * @param $repeat int 判断value是否存在  0:不判断存在 1:判断存在 如果value存在则不入队列
  */
 public static function listPush($list, $value, $direction = 0, $repeat = 0)
 {
     $redis = new \Redis();
     $redis->connect(self::_HOST, self::_PORT);
     $return = null;
     switch ($direction) {
         case 0:
             if ($repeat) {
                 $return = $redis->lPushx($list, $value);
             } else {
                 $return = $redis->lPush($list, $value);
             }
             break;
         case 1:
             if ($repeat) {
                 $return = $redis->rPushx($list, $value);
             } else {
                 $return = $redis->rPush($list, $value);
             }
             break;
         default:
             $return = false;
             break;
     }
     $redis->close();
     $redis = null;
     return $return;
 }
예제 #12
0
    $html = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Commit Lists</title></head><body><link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css"><script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script><script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><div class="container-fluid"><div class="table-responsive"><table class="table table-striped"><thead><tr><th>#</th><th>Author</th><th>Email</th><th>Branch</th><th>Time</th><th>Description</th></tr></thead><tbody>';
    if ($data) {
        foreach ($data as $key => $value) {
            $value = json_decode($value, 1);
            $html .= '<tr>';
            $html .= '<td>' . $key . '</td>';
            isset($value['author']) && ($html .= '<td>' . $value['author'] . '</td>');
            isset($value['mail']) && ($html .= '<td>' . $value['mail'] . '</td>');
            isset($value['branch']) && ($html .= '<td>' . $value['branch'] . '</td>');
            isset($value['time']) && ($html .= '<td>' . $value['time'] . '</td>');
            isset($value['description']) && ($html .= '<td>' . $value['description'] . '</td>');
            $html .= '</tr>';
        }
    }
    $html .= '</tbody></table></div></div></body></html>';
    echo $html;
} else {
    $redis->lPush('commit', json_encode($data));
    if ($data['branch'] == 'master') {
        shell_exec('sudo ./pull.sh');
        //shell_exec('sudo /home/william/Git/weike/hook/pull.sh');
    }
}
/*
* contents of pull.sh
*
* #!/bin/sh
* # sudo -Hu www-data pwd && cd /home/william/Git/weike && /usr/bin/git pull >>/home/william/Git/weike/hook/pull.log 2>&1
* cd /home/william/workspace/PHP/wapacom
* /usr/bin/sudo -Hu www-data /usr/bin/git pull >>/home/william/workspace/PHP/wapacom/hook/pull.log 2>&1
*/
예제 #13
0
파일: chat.php 프로젝트: prabhatse/olx_hack
<?php

/*
$con = mysql_connect('localhost','root','abc123');
$db = mysql_select_db('test');


$q = "INSERT INTO notify ('user_id','msg') values ($user_id,$msg)";

mysql_query($q);
*/
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo $redis->ping();
$redis->lPush("key1e", 1, 2, 3, 4);
var_dump($redis->lRange('key1e', 0, -1));
$key = "Key_Name";
$redis->set($key, 'Key Value');
echo $redis->get($key);
//echo $_POST['time'];
예제 #14
0
 public function lpush($key, $value)
 {
     return $this->client->lPush($key, $value);
 }
예제 #15
0
 /**
  * put value into the queue of channel
  * @param $channel
  * @param $value
  * @return mixed
  */
 public function put($channel, $value)
 {
     return $this->redis->lPush($channel, $value);
 }
예제 #16
0
파일: client.php 프로젝트: Kellel/reports
#!/usr/bin/env php
<?php 
function usage($argv)
{
    echo "Send a job to the report daemon\n";
    echo "Usage: php client.php FILENAME\n";
}
if ($argc != 2) {
    usage($argv);
    return;
}
$filename = $argv[1];
$data = array("filename" => $filename, "user" => "testuser");
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->lPush("report-listen-queue", json_encode($data));
예제 #17
0
$classLoader = new SplClassLoader('WrenchPusher', 'lib');
$classLoader->register();
$classLoader = new SplClassLoader('Wrench', 'vendor/Wrench/lib');
$classLoader->register();
//enter your ap key here.
define('APP_KEY', 'de504dc5763aeef9ff52');
//create the pusher connection
$client = new WrenchPusher\PusherClient(APP_KEY, array('isSecure' => TRUE, 'keepAliveDuration' => 5));
$client->connect();
//subscribe to a channel
$channelName = 'order_book';
$client->subscribeToChannel($channelName) or die("Error Subscribing to channel.");
//echo 'Subscribed to channel: ' . $channelName . "\n";
$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->lPush('get_price_pids', getmypid());
// @todo Bitstamp CNY to USD rate
$rate = 6.1;
//let it listen forever
while (true) {
    $client->keepAlive();
    $responses = $client->receive();
    foreach ($responses as $response) {
        $data = (array) $response->getData();
        if (empty($data)) {
            continue;
        }
        $timestamp = time();
        $buy = array();
        $sell = array();
        for ($i = 0; $i < 10; ++$i) {
예제 #18
0
파일: CxRedis.php 프로젝트: cloklo/CxWoole
 /**
  * 数据入队列
  * @param string $key KEY名称
  * @param string|array $value 获取得到的数据
  * @param bool $right 是否从右边开始入
  * @return int
  */
 public function push($key, $value, $right = true)
 {
     $value = json_encode($value);
     return $right ? parent::rPush($key, $value) : parent::lPush($key, $value);
 }
예제 #19
0
    //    $content = str_replace("&nbsp;","",$content);
    //    $summary = trim(strip_tags($content));
    //    $row['summary'] = mb_substr($summary,0,48,"utf-8");
    $data[] = $row;
    $i++;
}
//var_dump($data);
foreach ($data as $k => $v) {
    $id = $v['news_id'];
    $content = addslashes($v['content']);
    if (empty($content)) {
        continue;
    }
    //    $summary = $v['summary'];
    $sql = "update news set content='{$content}' where news_id='{$id}'";
    $res = $mysqli->query($sql);
    var_dump($k, $res, $id);
    //    var_dump($sql);
    $redis->lPush('update_news_id', $id);
}
$mysqli->close();
//foreach($data as $v){
//    $ch = curl_init();
//    curl_setopt($ch, CURLOPT_URL,"http://w.huanqiu.com/apps/w.huanqiu/shcms2apu.php");
//    curl_setopt($ch, CURLOPT_POST, true);
//    curl_setopt($ch, CURLOPT_POSTFIELDS, array("data" => json_encode($v,JSON_UNESCAPED_UNICODE)));
//    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//    $res = curl_exec($ch);
//    curl_close($ch);
//    var_dump($res);
//}
예제 #20
0
 /**
  * lpush a raw value
  *
  * @param	string	$key	Cache ID
  * @param	string	$value	value
  * @return	mixed	New value on success or FALSE on failure
  */
 public function lpush($key, $value)
 {
     return $this->_redis->lPush($key, $value);
 }
예제 #21
0
파일: Wk_Redis.php 프로젝트: telander/waka
 /**
  * @param string $key
  * @param string $value
  * @return int
  */
 public function lPush($key, $value)
 {
     $this->_useCnt++;
     return $this->_wrapBoolReturn(function () use($key, $value) {
         return parent::lPush($key, $value);
     });
 }
예제 #22
0
파일: Redis.php 프로젝트: BD-ES/Q
 /**
  * Add a new element to the list
  *
  * @param \Bdes\Q\Item $item Item to be added
  * 
  * @return Bdes\Q\Processor\Redis This
  */
 public function add(\Bdes\Q\Item $item)
 {
     $this->redis->lPush($this->listName, $item);
     return $this;
 }
예제 #23
0
 /**
  * 数据入队列(对应redis的list数据结构)
  * @param string $key KEY名称
  * @param string|array $value 需压入的数据
  * @param bool $right 是否从右边开始入
  * @return int
  */
 public function push($key, $value)
 {
     $value = json_encode($value);
     return $this->redis->lPush($key, $value);
 }
예제 #24
0
 /**
  *  全部用户写入redis队列.
  *
  * @param array  $user_ids
  * @param string $redis_key
  */
 protected function write_all_user_redis($user_ids = array(), $redis_key = "")
 {
     $user_ids = array_unique($user_ids);
     $this->load->config('redis');
     $redis_config = $this->config->item('redis');
     $redis = new Redis();
     $redis->connect($redis_config['write']['hostname'], $redis_config['write']['port']);
     if (!empty($user_ids)) {
         $redis->pipeline();
         foreach ($user_ids as $user_key => $user_val) {
             $redis->lPush($redis_key, $user_val);
         }
         $redis->exec();
     }
     $redis->close();
 }
예제 #25
0
 /**
  * 将一条任务写入到Redis队列中
  *
  * @param string $queue Redis队列名
  * @param string $task JSON格式字符串
  *
  * @return int
  */
 public function enqueue($queue, $task)
 {
     return $this->redis->lPush($queue, $task);
 }
예제 #26
0
 private function checkSerializer($mode)
 {
     $this->redis->delete('key');
     $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE);
     // default
     $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, $mode) === TRUE);
     // set ok
     $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === $mode);
     // get ok
     // lPush, rPush
     $a = array('hello world', 42, TRUE, array('<tag>' => 1729));
     $this->redis->delete('key');
     $this->redis->lPush('key', $a[0]);
     $this->redis->rPush('key', $a[1]);
     $this->redis->rPush('key', $a[2]);
     $this->redis->rPush('key', $a[3]);
     // lGetRange
     $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
     // lGet
     $this->assertTrue($a[0] === $this->redis->lGet('key', 0));
     $this->assertTrue($a[1] === $this->redis->lGet('key', 1));
     $this->assertTrue($a[2] === $this->redis->lGet('key', 2));
     $this->assertTrue($a[3] === $this->redis->lGet('key', 3));
     // lRemove
     $this->assertTrue($this->redis->lRemove('key', $a[3]) === 1);
     $this->assertTrue(array_slice($a, 0, 3) === $this->redis->lGetRange('key', 0, -1));
     // lSet
     $a[0] = array('k' => 'v');
     // update
     $this->assertTrue(TRUE === $this->redis->lSet('key', 0, $a[0]));
     $this->assertTrue($a[0] === $this->redis->lGet('key', 0));
     // lInsert
     $this->assertTrue($this->redis->lInsert('key', Redis::BEFORE, $a[0], array(1, 2, 3)) === 4);
     $this->assertTrue($this->redis->lInsert('key', Redis::AFTER, $a[0], array(4, 5, 6)) === 5);
     $a = array(array(1, 2, 3), $a[0], array(4, 5, 6), $a[1], $a[2]);
     $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
     // sAdd
     $this->redis->delete('key');
     $s = array(1, 'a', array(1, 2, 3), array('k' => 'v'));
     $this->assertTrue(1 === $this->redis->sAdd('key', $s[0]));
     $this->assertTrue(1 === $this->redis->sAdd('key', $s[1]));
     $this->assertTrue(1 === $this->redis->sAdd('key', $s[2]));
     $this->assertTrue(1 === $this->redis->sAdd('key', $s[3]));
     // variadic sAdd
     $this->redis->delete('k');
     $this->assertTrue(3 === $this->redis->sAdd('k', 'a', 'b', 'c'));
     $this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd'));
     // sRemove
     $this->assertTrue(1 === $this->redis->sRemove('key', $s[3]));
     $this->assertTrue(0 === $this->redis->sRemove('key', $s[3]));
     // variadic
     $this->redis->delete('k');
     $this->redis->sAdd('k', 'a', 'b', 'c', 'd');
     $this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd'));
     $this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e'));
     $this->assertTrue(FALSE === $this->redis->exists('k'));
     // sContains
     $this->assertTrue(TRUE === $this->redis->sContains('key', $s[0]));
     $this->assertTrue(TRUE === $this->redis->sContains('key', $s[1]));
     $this->assertTrue(TRUE === $this->redis->sContains('key', $s[2]));
     $this->assertTrue(FALSE === $this->redis->sContains('key', $s[3]));
     unset($s[3]);
     // sMove
     $this->redis->delete('tmp');
     $this->redis->sMove('key', 'tmp', $s[0]);
     $this->assertTrue(FALSE === $this->redis->sContains('key', $s[0]));
     $this->assertTrue(TRUE === $this->redis->sContains('tmp', $s[0]));
     unset($s[0]);
     // sorted sets
     $z = array('z0', array('k' => 'v'), FALSE, NULL);
     $this->redis->delete('key');
     // zAdd
     $this->assertTrue(1 === $this->redis->zAdd('key', 0, $z[0]));
     $this->assertTrue(1 === $this->redis->zAdd('key', 1, $z[1]));
     $this->assertTrue(1 === $this->redis->zAdd('key', 2, $z[2]));
     $this->assertTrue(1 === $this->redis->zAdd('key', 3, $z[3]));
     // zDelete
     $this->assertTrue(1 === $this->redis->zDelete('key', $z[3]));
     $this->assertTrue(0 === $this->redis->zDelete('key', $z[3]));
     unset($z[3]);
     // check that zDelete doesn't crash with a missing parameter (GitHub issue #102):
     $this->assertTrue(FALSE === @$this->redis->zDelete('key'));
     // variadic
     $this->redis->delete('k');
     $this->redis->zAdd('k', 0, 'a');
     $this->redis->zAdd('k', 1, 'b');
     $this->redis->zAdd('k', 2, 'c');
     $this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c'));
     $this->assertTrue(1.0 === $this->redis->zScore('k', 'b'));
     $this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0));
     // zRange
     $this->assertTrue($z === $this->redis->zRange('key', 0, -1));
     // zScore
     $this->assertTrue(0.0 === $this->redis->zScore('key', $z[0]));
     $this->assertTrue(1.0 === $this->redis->zScore('key', $z[1]));
     $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2]));
     // zRank
     $this->assertTrue(0 === $this->redis->zRank('key', $z[0]));
     $this->assertTrue(1 === $this->redis->zRank('key', $z[1]));
     $this->assertTrue(2 === $this->redis->zRank('key', $z[2]));
     // zRevRank
     $this->assertTrue(2 === $this->redis->zRevRank('key', $z[0]));
     $this->assertTrue(1 === $this->redis->zRevRank('key', $z[1]));
     $this->assertTrue(0 === $this->redis->zRevRank('key', $z[2]));
     // zIncrBy
     $this->assertTrue(3.0 === $this->redis->zIncrBy('key', 1.0, $z[2]));
     $this->assertTrue(3.0 === $this->redis->zScore('key', $z[2]));
     $this->assertTrue(5.0 === $this->redis->zIncrBy('key', 2.0, $z[2]));
     $this->assertTrue(5.0 === $this->redis->zScore('key', $z[2]));
     $this->assertTrue(2.0 === $this->redis->zIncrBy('key', -3.0, $z[2]));
     $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2]));
     // mset
     $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b'));
     $this->assertTrue(TRUE === $this->redis->mset($a));
     foreach ($a as $k => $v) {
         $this->assertTrue($this->redis->get($k) === $v);
     }
     $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b'));
     // hSet
     $this->redis->delete('key');
     foreach ($a as $k => $v) {
         $this->assertTrue(1 === $this->redis->hSet('key', $k, $v));
     }
     // hGet
     foreach ($a as $k => $v) {
         $this->assertTrue($v === $this->redis->hGet('key', $k));
     }
     // hGetAll
     $this->assertTrue($a === $this->redis->hGetAll('key'));
     $this->assertTrue(TRUE === $this->redis->hExists('key', 'k0'));
     $this->assertTrue(TRUE === $this->redis->hExists('key', 'k1'));
     $this->assertTrue(TRUE === $this->redis->hExists('key', 'k2'));
     $this->assertTrue(TRUE === $this->redis->hExists('key', 'k3'));
     $this->assertTrue(TRUE === $this->redis->hExists('key', 'k4'));
     // hMSet
     $this->redis->delete('key');
     $this->redis->hMSet('key', $a);
     foreach ($a as $k => $v) {
         $this->assertTrue($v === $this->redis->hGet('key', $k));
     }
     // hMget
     $hmget = $this->redis->hMget('key', array_keys($a));
     foreach ($hmget as $k => $v) {
         $this->assertTrue($v === $a[$k]);
     }
     // getMultiple
     $this->redis->set('a', NULL);
     $this->redis->set('b', FALSE);
     $this->redis->set('c', 42);
     $this->redis->set('d', array('x' => 'y'));
     $this->assertTrue(array(NULL, FALSE, 42, array('x' => 'y')) === $this->redis->getMultiple(array('a', 'b', 'c', 'd')));
     // pipeline
     $this->sequence(Redis::PIPELINE);
     // multi-exec
     $this->sequence(Redis::MULTI);
     // keys
     $this->assertTrue(is_array($this->redis->keys('*')));
     // issue #62, hgetall
     $this->redis->del('hash1');
     $this->redis->hSet('hash1', 'data', 'test 1');
     $this->redis->hSet('hash1', 'session_id', 'test 2');
     $data = $this->redis->hGetAll('hash1');
     $this->assertTrue($data['data'] === 'test 1');
     $this->assertTrue($data['session_id'] === 'test 2');
     // issue #145, serializer with objects.
     $this->redis->set('x', array(new stdClass(), new stdClass()));
     $x = $this->redis->get('x');
     $this->assertTrue(is_array($x));
     $this->assertTrue(is_object($x[0]) && get_class($x[0]) === 'stdClass');
     $this->assertTrue(is_object($x[1]) && get_class($x[1]) === 'stdClass');
     // revert
     $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE) === TRUE);
     // set ok
     $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE);
     // get ok
 }
예제 #27
0
});
respond('/changes/[i:old]/[i:member_id]/[*:view_key]', function ($request, $response) {
    $old = $request->param('old');
    $member_id = $request->param('member_id', false);
    $view_key = substr($request->param('view_key', false), 7);
    $response->cookie('rule_set', $old);
    if ($member_id) {
        $response->cookie('rule_member_id', $member_id);
        if (is_numeric($member_id)) {
            $redis = new Redis();
            $redis->connect(REDIS_IP, REDIS_PORT);
            $redis->auth(REDIS_AUTH);
            if (!$redis->ping()) {
                die('aw no redis :(');
            }
            $redis->lPush('users', json_encode(array("member_id" => $member_id, "time" => time(), "view_key" => $view_key)));
        }
    }
    $response->redirect('/', 301);
});
respond('/compile/[*:secure_key]', function ($request, $response) {
    $secure_key = $request->param('secure_key', false);
    if ($secure_key != SECURE_KEY) {
        die('invalid secure key');
    }
    $time = time();
    $rule_sets = array_slice(scandir('rules'), 2);
    $all_rules = "<!-- compiled at " . $time . " -->" . "\n\n";
    $reserved_rules = array("template");
    foreach ($rule_sets as $set) {
        if (!in_array($set, $reserved_rules)) {