thinkphp3.2.3 版本使用redis缓存添加认证
public function __construct($options=array()) {if ( !extension_loaded('redis') ) {
E(L(
'_NOT_SUPPORT_').':redis');
}
$options = array_merge(array (
'host' => C('REDIS_HOST') ? : '127.0.0.1',
'port' => C('REDIS_PORT') ? : 6379,
'timeout' => C('DATA_CACHE_TIMEOUT') ? : false,
'auth' => C('REDIS_AUTH_PASSWORD') ? C('REDIS_AUTH_PASSWORD'):null,//auth认证的密码
'persistent' => false,
),$options);
$this->options =$options;
$this->options['expire'] =isset($options['expire'])?$options['expire']: C('DATA_CACHE_TIME');
$this->options['prefix'] =isset($options['prefix'])?$options['prefix']: C('DATA_CACHE_PREFIX');
$this->options['length'] =isset($options['length'])?$options['length']: 0;
$func = $options['persistent'] ? 'pconnect' : 'connect';
$this->handler= new \Redis;
$options['timeout'] === false ?
$this->handler->$func($options['host'], $options['port']) :
$this->handler->$func($options['host'], $options['port'], $options['timeout']);
if($this->options['auth']!=null)
{
$this->handler->auth($this->options['auth']); //说明有配置redis的认证配置密码 需要认证一下
}
}
页:
[1]