0

PHP连接Redis服务器,出现NOAUTH Authentication required错误

好不容易安装、配置完Redis服务器和扩展库,写完PHP代码后,提示“NOAUTH Authentication required”错误,如下图所示

这是因为开启了Redis服务器的密码认证,所以完整的链接,验证PHP代码如下:
<?php  
   $redis = new Redis(); 
   $redis->connect('127.0.0.1', 6379);   //连接Redis服务器

   $redis->auth('mypasswords123sdfeak'); //密码验证

   $redis->select(2);   //选择数据库2
   $redis->set( "testKey" , "Hello jbsage.com");   //设置测试key
   echo $redis->get("testKey");   //输出value
?>
上面的代码就完成了PHP连接Redis,Redis密码验证、指定某一Redis数据库,SET/GET操作,完美!