예제 #1
1
 public function __construct($host = '127.0.0.1', $port = 6379, $timeout = 0.0, $pass = null)
 {
     $redis = new \redis();
     $redis->pconnect($host, $port, $timeout);
     if ($pass) {
         $redis->auth($pass);
     }
     $this->redis = $redis;
 }
예제 #2
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;
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * redis 链接
  */
 private function redis()
 {
     $cfg = $this->getRedisHost();
     try {
         $redis = new redis();
         $redis->pconnect($cfg['host'], $cfg['port'], 0);
         if ($cfg['auth']) {
             $redis->auth($cfg['auth']);
         }
         $this->redis = $redis;
         $this->redis->ping();
     } catch (Exception $e) {
         $this->log($e->getMessage() . ' now retrying');
         sleep(1);
         //如果报错等一秒再重连
         $this->redis();
     }
 }
예제 #5
0
 public function __construct()
 {
     $redis = new \redis();
     $redis->pconnect('127.0.0.1', '6379', '0.0');
     $this->redis = $redis;
     $this->access_token = $redis->get('access_token');
     if (!$this->access_token) {
         $appId = Config::get('wechat.app_id');
         $appSecret = Config::get('wechat.secret');
         $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appId . '&secret=' . $appSecret . '';
         $res = Curl::get($url);
         $arr = json_decode($res);
         $access_token = $arr->access_token;
         $time_out = $arr->expires_in;
         $this->redis->set('access_token', $access_token);
         $this->redis->expire('access_token', $time_out);
         $this->access_token = $access_token;
     }
 }
예제 #6
0
<?php

/* 这里替换为连接的实例host和port */
$host = "127.0.0.1";
$port = 6379;
/* 这里替换为实例id和实例password,没有则注释掉 */
/*$user = "******";
$pwd = "xxxxxxx";*/
$Redis = new redis();
//$Redis->pconnect('127.0.0.1', 6379);
if ($Redis->pconnect($host, $port) == false) {
    die($Redis->getLastError());
}
//如果没有账户密码,就注释掉
/*if ($Redis->auth($user . ":" . $pwd) == false) {
    die($Redis->getLastError());
}*/
file_put_contents('./redis.json', '');
$it = NULL;
/* Initialize our iterator to NULL */
$Redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
/* retry when we get no keys back */
while ($keys = $Redis->scan($it)) {
    $out = '';
    foreach ($keys as $key) {
        //echo $Redis->type($key),"\n";
        $arr = array();
        $type = $Redis->type($key);
        $expire = $Redis->ttl($key);
        switch ($type) {
            case $Redis::REDIS_STRING:
예제 #7
0
<?php

$con = mysql_connect('localhost', 'root', '123');
mysql_select_db('qxy_istrone');
$sql = 'select ID, post_title, post_content from wp_posts where post_status= "publish" and post_title != "" order by post_date desc limit 30';
$query = mysql_query($sql);
mysql_close($con);
$redis = new redis();
$redis->pconnect('127.0.0.1');
$real_data = array();
$i = 0;
while ($data = mysql_fetch_assoc($query)) {
    $real_data['{{link_' . $i . '}}'] = 'http://7magic.istrone.com/f/' . $data['ID'];
    $real_data['{{text_' . $i . '}}'] = $data['post_title'];
    $redis->set($data['ID'], json_encode(array('{{title}}' => $data['post_title'], '{{content}}' => $data['post_content'], '{{src_url}}' => 'http://istrone.com/?p=' . $data['ID'])));
    $i++;
}
$redis->set('home', json_encode($real_data));
$redis_get_binary = $redis->get('home');
echo $redis_get_binary . "\n";
$redis->close();
예제 #8
0
파일: ssdb.php 프로젝트: tianyunchong/php
<?php

/**
 * 查询下关键词信息的ssdb的存储
 */
$type = "pd";
$keyword = "冰岛鲨鱼肝油软胶囊";
$key = 'wd:' . $type . ':' . $keyword;
$redis = new redis();
$redis->pconnect('172.17.16.47', 6380, 1);
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
$rs = $redis->get($key);
var_dump($rs);