成都网站建设设计

将想法与焦点和您一起共享

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://chengdu.cdxwcx.cn/article/ieidjg.html