php 判断redis是否有效用 在NOAUTH Authentication required 的解决办法
有一个需求必须使用到redis,而且必须配密码访问。按照一般连接方法会出现
NOAUTH Authentication required 抛出异常 造成其他php业务逻辑中断被迫抛出异常。这需要我们进行改造连接实例的方法。以下是使用Thinkphp的demo实例。
$this->redis = new \Redis();
$redis_conf = config('redis');
$this->redis->connect($redis_conf['host'],$redis_conf['port']);
$this->redis_status =$this->redis->auth($redis_conf['password']) or false;
if($this->redis_status){
$this->redis->select($redis_conf['select']);
}