Home  >  Article  >  Backend Development  >  php 如何连接有密码的Redis服务器

php 如何连接有密码的Redis服务器

WBOY
WBOYOriginal
2016-06-06 20:10:471312browse

//一般使用下面代码连接Redis

<code>$redis = new redis();  
$result = $redis->connect('127.0.0.1', 6379);  </code>

但配置密码后的Redis呢,怎么连接

回复内容:

//一般使用下面代码连接Redis

<code>$redis = new redis();  
$result = $redis->connect('127.0.0.1', 6379);  </code>

但配置密码后的Redis呢,怎么连接

<code>  //实例化  
  $redis = new Redis();  
  //连接服务器  
  $redis->connect("localhost");  
  //授权  
  $redis->auth("passwd");  
  //相关操作  
  $redis->set("name","father");  
  $data = $redis->key("*");  
  var_dump($data);  </code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn