class PhpRedis extends redis{
//redis默认有16张分表
static $dbs = array('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',);
public function __construct(){
try{
//redis主机,连接端口
$this->connect($redis_cachehost, $redis_cacheport);
//连接密码
$this->auth($redis_passport);
}cache(Exception $e){
log_message('REDIS ERROR', $e->__toString(), 'redis');
}
}
//静态实例化
static private $obCore = '';
static function getInstance(){
if(self::$obCore == NULL){
self::$obCore = new self();
}
return self::$obCore;
}
}
//附:log_message()方法,用于生成日志文件
function log_message($type, $var, $file = '')
{
$dir = ROOT . '/log/'; //ROOT为根目录
if (!$file) {
$dir .= date("Y") . '/' . date("m") . '/' . date('d');
mkdirs($dir);
$file = $dir . '/' . date("Ymd") . ".log";
} else {
$file = $dir . TEMPLATE . '_' . $file . '.log';
}
$sh = fopen($file, "a");
$var = "[$type] " . date('Y-m-d H:i:s') . ' : ' . $var . "\n";
fwrite($sh, $var, strlen($var));
fclose($sh);
}
转载于:https://my.oschina.net/u/2380669/blog/500259