예제 #1
0
 public function __construct()
 {
     if (self::$reObj === null) {
         if (!extension_loaded('redis')) {
             die('服务器不支持redis扩展!');
         }
         $reObj = new \redis();
         $config = \System\Entrance::config('REDIS_CONFIG');
         $host = $config['host'];
         $port = $config['port'];
         $auth = $config['auth'];
         if ($config['connectType'] == 'connect') {
             $connect = $reObj->connect($host, $port);
         } else {
             $connect = $reObj->pconnect($host, $port);
         }
         if (!empty($auth)) {
             if (!$reObj->auth($auth)) {
                 die('redis密码错误!');
             }
         }
         if (!$connect) {
             die('redis服务器连接失败!');
         }
         self::$reObj = $reObj;
     }
     return self::$reObj;
 }
예제 #2
0
 public function info()
 {
     $server = $this->model->one(intval($this->input->get('id')));
     $redis = new \redis();
     if ($redis->connect($server->host, $server->port, 30) == false) {
         echo "Redis '{$server->host}' Connected Failed. \n";
         exit($redis->getLastError());
     }
     if ($server->password) {
         if ($redis->auth($server->password) == false) {
             echo "Redis '{$server->host}' Password Is Incorrect. \n";
             exit($redis->getLastError());
         }
     }
     $data['keyspace'] = $redis->info('keyspace');
     $data['memory'] = $redis->info('memory');
     $data['clients'] = $redis->info('clients');
     //$data['slow'] = $redis->slowLog('get',10);
     $redis->close();
     $result = $this->db('bs')->query('select * from en_server_redis_data where server_id=' . $server->id . ' order by created asc ')->result();
     $data['chart_memory_data'] = [];
     $data['chart_memory_time'] = [];
     $data['chart_connection_data'] = [];
     $data['chart_connection_time'] = [];
     foreach ($result as $rs) {
         $data['chart_memory_data'][] = round($rs->memory / 1024 / 1024, 2);
         $data['chart_memory_time'][] = date('H:i', $rs->created);
         $data['chart_connection_data'][] = intval($rs->connection);
         $data['chart_connection_time'][] = date('H:i', $rs->created);
     }
     $data['server'] = $server;
     $this->output->view('monitor/redis/server_info', $data);
 }
예제 #3
0
function connredis()
{
    static $r = null;
    if ($r !== null) {
        return $r;
    }
    $r = new redis();
    $r->connect('localhost');
    return $r;
}
예제 #4
0
 public function testRedis()
 {
     $this->assertTrue(in_array('redis', get_loaded_extensions()), '缺少redis extension');
     $cfg = (include ROOT_PATH . '/../config/sysconfig.php');
     $params = array('server', 'port', 'timeout');
     foreach ($params as $param) {
         $this->assertArrayHasKey($param, $cfg['redisConf'], 'redis缺少' . $param . '配置');
     }
     $r = new redis();
     $this->assertTrue($r->connect($cfg['redisConf']['server'], $cfg['redisConf']['port'], $cfg['redisConf']['timeout']), 'redis连接失败');
 }
예제 #5
0
 /**
  * Construct
  *
  * Do not use this directly. You can use getInstance() instead.
  * @param string $url url of Redis
  * @return void
  */
 function __construct($url)
 {
     //$config['url'] = 'redis://localhost:6379/1';
     $config['url'] = is_array($url) ? reset($url) : $url;
     if (!class_exists('Redis')) {
         return $this->status = false;
     }
     try {
         $this->redis = new Redis();
         $info = parse_url($url);
         $this->redis->connect($info['host'], $info['port'], 0.15);
         if (isset($info['user']) || isset($info['pass'])) {
             $this->redis->auth(isset($info['user']) ? $info['user'] : $info['pass']);
         }
         if (isset($info['path']) && ($dbnum = intval(substr($info['path'], 1)))) {
             $this->redis->select($dbnum);
         }
         return $this->status = true;
     } catch (RedisException $e) {
         return $this->status = false;
     }
 }
예제 #6
0
파일: Oredis.php 프로젝트: superbogy/cargo
 public function __construct($config)
 {
     $redis = new \redis();
     if (isset($config['PCONNECT'])) {
         $redis->pconnect($config['HOST'], $config['PORT'], $config['TIMEOUT']);
     } else {
         $redis->connect($config['HOST'], $config['PORT'], $config['TIMEOUT']);
     }
     $redis->setOption(\redis::OPT_SERIALIZER, \redis::SERIALIZER_NONE);
     $redis->select($config['DB']);
     $this->redis = $redis;
     self::$config = $config;
 }
예제 #7
0
 public function test_redis($loop_times)
 {
     $tbname = $this->tbname;
     $dbname = $this->dbname;
     $start_time = microtime(true);
     for ($i = 0; $i < $loop_times; $i++) {
         ##   for ($j = 0; $j < 5; $j++){
         $redis = new redis();
         $redis->connect('127.0.0.1', 6379);
         $redis->hGetAll("{$tbname}");
         ##    }
     }
     $end_time = microtime(true);
     $rstime = $end_time - $start_time;
     return $rstime;
 }
예제 #8
0
파일: monitor.php 프로젝트: beyondye/ENPHP
 public function redisData()
 {
     $result = $this->db('bs')->query("select * from en_server_redis")->result();
     foreach ($result as $server) {
         $redis = new \redis();
         if ($redis->connect($server->host, $server->port, 30) == false) {
             echo "Redis '{$server->host}' Connected Failed. \n";
             continue;
         }
         if ($server->password) {
             if ($redis->auth($server->password) == false) {
                 echo "Redis '{$server->host}' Password Is Incorrect. \n";
                 $redis->close();
                 continue;
             }
         }
         $memory = $redis->info('memory');
         $clients = $redis->info('clients');
         $redis->close();
         $this->db('bs')->insert('en_server_redis_data', ['server_id' => $server->id, 'memory' => $memory['used_memory'], 'connection' => $clients['connected_clients'], 'created' => time()]);
     }
     $del = time() - 3600 * 24;
     $this->db('bs')->delete('en_server_redis_data', " created<{$del} ");
 }
예제 #9
0
<?php

header('Access-Control-Allow-Origin:*');
$IM = 'Im.malu.me';
$IM_ROOM = array('C1' => 0, 'C2' => 0, 'M1' => 0, 'M2' => 0);
$redis = new redis();
$redis->connect('REDIS_HOST', REDIS_PORT);
$result = $redis->auth('REDIS_PASS');
if ($result) {
    $pipe = $redis->multi(Redis::PIPELINE);
    foreach ($IM_ROOM as $key => $value) {
        $pipe->lrange($IM . '_' . $key, 0, 0);
    }
    $result = $pipe->exec();
    //var_dump($result);
}
if ($result) {
    $i = 0;
    foreach ($IM_ROOM as $key => $value) {
        if ($result[$i]) {
            $r = explode('-', $result[$i][0]);
            $IM_ROOM[$key] = $r[0];
        }
        $i++;
    }
    //var_dump($IM_ROOM);
}
echo json_encode($IM_ROOM);
예제 #10
0
<?php

header("content-type:text/html;charset=utf-8");
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
$mywatchkey = $redis->get("mywatchkey");
$rob_total = 10;
//抢购数量
if ($mywatchkey < $rob_total) {
    $redis->watch("mywatchkey");
    $redis->multi();
    //设置延迟,方便测试效果。
    sleep(5);
    //插入抢购数据
    $redis->hSet("mywatchlist", "user_id_" . mt_rand(1, 9999), time());
    $redis->set("mywatchkey", $mywatchkey + 1);
    $rob_result = $redis->exec();
    if ($rob_result) {
        $mywatchlist = $redis->hGetAll("mywatchlist");
        echo "抢购成功!<br/>";
        echo "剩余数量:" . ($rob_total - $mywatchkey - 1) . "<br/>";
        echo "用户列表:<pre>";
    } else {
        echo "手气不好,再抢购!";
        exit;
    }
}
?>
  
예제 #11
0
파일: redis2.php 프로젝트: myersguo/phpio
    {
    }
    function get($key)
    {
    }
}
class myredis
{
    function __construct($redis)
    {
        $this->_redis = $redis;
    }
    public function __call($name, $args)
    {
        return call_user_func_array(array($this->_redis, $name), $args);
    }
}
$redis = new redis();
$redis->connect('127.0.0.1');
$redis->set('key1', rand());
$redis->get('key1');
$myredis = new myredis($redis);
$myredis->set('key2', rand());
$myredis->get('key2');
$redis2 = new redis2();
$redis2->connect('127.0.0.1');
$redis2->set('key3', rand());
$redis2->get('key3');
$myredis2 = new myredis($redis2);
$myredis2->set('key4', rand());
$myredis2->get('key4');
예제 #12
0
파일: Redis.php 프로젝트: pan269/php-webim
 function __construct($host = '127.0.0.1', $port = 6379, $timeout = 0.0)
 {
     $redis = new \redis();
     $redis->connect($host, $port, $timeout);
     $this->redis = $redis;
 }
예제 #13
0
function connectRedis($host, $port, $pwd = None)
{
    $r = new redis();
    $r->connect($host, $port);
    if ($pwd) {
        $r->auth($pwd);
    }
    return $r;
}
예제 #14
0
<?php

header('Access-Control-Allow-Origin:*');
$IM = 'Im.malu.me';
$IM_ROOM = array('C1' => 0, 'C2' => 0, 'M1' => 0, 'M2' => 0, 'AI' => 0);
$redis = new redis();
$redis->connect('localhost', 6379);
$result = $redis->auth('REDIS_PASS');
if ($result) {
    $pipe = $redis->multi(Redis::PIPELINE);
    foreach ($IM_ROOM as $key => $value) {
        $pipe->lrange($IM . '_' . $key, 0, 0);
    }
    $result = $pipe->exec();
    //var_dump($result);
}
if ($result) {
    $i = 0;
    foreach ($IM_ROOM as $key => $value) {
        if ($result[$i]) {
            $r = explode('-', $result[$i][0]);
            $IM_ROOM[$key] = $r[0];
        }
        $i++;
    }
    //var_dump($IM_ROOM);
}
$json_result = json_encode($IM_ROOM);
echo $json_result;
//$rlocal->setex($IM,2,$json_result);
예제 #15
0
            return NULL;
        }
        if (strcasecmp($method, "ds_mget") == 0 || strcasecmp($method, "ds_hmget") == 0) {
            return $this->array_to_hash($data);
        }
        return $data;
    }
    public function __destruct()
    {
        if ($this->conn) {
            phpiredis_disconnect($this->conn);
        }
    }
}
$db = new redis("127.0.0.1", 6379);
$rc = $db->connect();
if (!$rc) {
    echo "can not connect redis server\r\n";
    exit;
}
$data = array("name" => "qiye", "age" => 18);
var_dump($db->hmset("key", $data));
var_dump($db->hgetall("key"));
/*
$value = array("name"=>"qiye", "age"=>18);
$db->hmset("user:1", $value);


$data = $db->multi(array('DEL test', 'SET test 1', 'GET test'));
print_r($data);
//echo $db->set("name", "value");
<?php

//链接redis数据库
$redis = new redis();
$redis->connect("localhost", 6379);
header("content-type:text/html;charset=utf-8");
//读取字典文件
$lines = file("/tmp/words.txt");
/*echo "<pre>";

	var_dump($lines);	

	echo "</pre>";*/
//获取到一个数组,数组的每一个元素就是每一行话
//批量处理这个数组的每个元素就是处理每一行话
foreach ($lines as $line) {
    $str = "";
    $line = rtrim($line, "\n");
    for ($i = 0; $i < strlen($line); $i++) {
        $str .= mb_substr($line, $i, 1, 'utf-8');
        //将分好的词插入到有序集合当中
        $redis->zadd('words', 0, $str);
    }
}
$words = $redis->zrange("words", 0, -1);
echo "<pre>";
var_dump($words);
echo "</pre>";
예제 #17
0
 *  Mac 安 装 量
 */
for ($i = 0; $i < count($install); $i++) {
    $mac_arr[] = explode(",", $install[$i]);
}
foreach ($mac_arr as $a => $b) {
    if (in_array("安装", $b)) {
        $mac[] = $b;
    }
}
foreach ($mac as $k => $v) {
    $name[] = substr($v[3], strrpos($v[3], '.'));
    $uname = array_unique($name);
    if (in_array(".exe", $uname)) {
        $re[$v[3]][] = $v;
    }
}
foreach ($re as $k => $v) {
    for ($i = 0; $i < count($v); $i++) {
        $mbr[$k] = count($v);
        $_mbr[] = count($v) . ',' . $k . ',' . $v[$i][1] . ',' . $data;
    }
}
for ($i = 0; $i < count($_mbr); $i++) {
    $_mbr_arr[] = explode(",", $_mbr[$i]);
}
$redis = new redis();
$redis->connect("127.0.0.1", 6379);
foreach ($_mbr_arr as $key => $val) {
    $redis->hset("install", $val[2], json_encode($val));
}
예제 #18
0
 /**
  * 天梯表演秀关联表初始化
  * @param gid    int  活动id
  * @param iid    int  参赛记录id
  * @param period int  活动排期数
  */
 private function init_show($gid, $iid, $schedule = 1)
 {
     $this->load->model('show/ladder_show_model', 'show_mod');
     $add_data = array();
     $add_data['wk_id'] = $iid;
     $add_data['gid'] = $gid;
     $add_data['period'] = $schedule;
     #$add_data['rank']   = $rank;
     $add_data['uid'] = $this->uid;
     $up_data = array('key' => 'wk_id', 'value' => $iid);
     $ret = $this->show_mod->add_ladder_show($add_data, $up_data);
     #初始化缓存
     if ($ret) {
         $redis = new redis();
         $redis->connect(REDIS_HOST, REDIS_PORT);
         $top_key = "ladder_show_top_" . $gid . '_' . $schedule;
         $top10_key = "ladder_show_top10_" . $gid . '_' . $schedule;
         $redis->del($top_key);
         $redis->del($top10_key);
     }
 }
예제 #19
0
<?php

//测试redis
$redis = new redis();
$redis->connect("192.168.2.102", 8880);
var_dump($re);
예제 #20
0
 public function get_rooms($rid = 100)
 {
     $redis = new redis();
     $redis->connect(REDIS_HOST, REDIS_PORT);
     $list = $redis->zRange("rooms_test_100", 0, 100, true);
     var_export($list);
     echo "##################";
 }
예제 #21
0
파일: index.php 프로젝트: geniushui/360biji
function redis_instance()
{
    $__redis = new redis();
    $__redis->connect('127.0.0.1', '6380');
    return $__redis;
}