网站建设资讯

NEWS

网站建设资讯

php连接redis类

  1. 代码:
    ]>
    */
    class phpredis extends Redis{
    public function connect($config){
        $host = $config['host'];
        $port = $config['port'];
        parent::connect($host,$port);
        $pass = @$config['pass']?:false;
        if($pass !== false){
            parent::auth($pass);
        }
        return $this;
    }
    }
  2. 测试:
    $config = array(
        'host'=>'192.168.8.81',
        'port'=>'6379',
        'pass'=>'123456'
    );
    $redis = new phpredis();
    $redis->connect($config);
    $redis->set('name','dollarphp');
    $ret = $redis->get('name');
    var_dump($ret);
  3. 输出:
    string(9) "dollarphp"

名称栏目:php连接redis类
网页网址:http://cdweb.net/article/ieidjg.html