欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP RedisSingleton

程序员文章站 2022-05-27 12:56:00
...

/**
* 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().'
';
}
}

}

相关标签: PHP RedisSingleton