当前位置:Gxlcms > PHP教程 > PHPRedisSingleton

PHPRedisSingleton

时间:2021-07-01 10:21:17 帮助过:28人阅读


/**
* Created by PhpStorm.
* User: xiongzai
* Date: 2016/5/17
* Time: 16:31
*/

namespace Think;

class RedisSingleton {

public $redis = null;

static protected $ins=null;

final protected function __construct(){
self::setRedis();
}

private function __clone(){}

static public function getInstance(){
if (self::$ins instanceof self) {
return self::$ins;
}
self::$ins=new self();
return self::$ins;
}


private function setRedis(){
try{
$redis = new \Redis();
$redis->connect( C('REDIS_HOST'), C('REDIS_PORT') );
$redis->auth( C('REDIS_AUTH') );
$this->redis = $redis;
unset($redis);
}catch(Exception $e){
echo $e->getMessage().'
';
}
}

}

人气教程排行