简体   繁体   English

REDIS PHP扩展连接错误

[英]REDIS php extension connect error

When I use redis PHP extension, I get the error, the host is 127.0.0.1 and the port is 6379. 当我使用redis PHP扩展时,出现错误,主机是127.0.0.1,端口是6379。

Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known. Redis :: connect():php_network_getaddresses:getaddrinfo失败:名称或服务未知。

I had the same issue happening sporadically on my local server with a number of attempted fixes yielding no resolution. 我在本地服务器上偶发地发生了同样的问题,尝试了许多修复程序,但均未解决。 This post here gave me an idea that seems to have finally fixed the problem. 这篇文章给了我一个想法,似乎终于解决了这个问题。

Basically, I have a number of vhosts set up on my local machine (running Ubuntu) which allows me to use domain names to access locally-run sites instead of the usual 'localhost/sitename' approach. 基本上,我在本地计算机(运行Ubuntu)上设置了多个虚拟主机,这使我可以使用域名访问本地运行的站点,而不是通常的“ localhost / sitename”方法。 As a result, I had no IP assigned to 'localhost' name. 结果,我没有将IP分配给“ localhost”名称。

This might not be the same root cause for the problem for you, but here's how I've solved mine: 这可能不是造成您问题的根本原因,但以下是我解决问题的方法:

  1. See what is the value of 'redis-host' in your redis config file (for me it's set to 'localhost'). 查看您的redis配置文件中的“ redis-host”的值是什么(对我而言,它设置为“ localhost”)。
  2. In your /etc/hosts file check that there's an IP assigned to that host name. 在/ etc / hosts文件中,检查是否为该主机名分配了IP。 (In your case, where redis-host is 127.0.0.1, check that there isn't some other host name assigned to that IP, like phpmyadmin, for example.) (在您的情况下,redis-host是127.0.0.1,请检查是否没有其他分配给该IP的主机名,例如phpmyadmin。)

Of course, as a sanity check, make sure your redis-server is up and running, try rebooting Apache in case you've made any config changes, etc. 当然,作为健全性检查,请确保您的redis服务器已启动并正在运行,并尝试重新启动Apache,以防万一您进行了任何配置更改,等等。

In my case, the issue was simple; 就我而言,问题很简单。 the host name was incorrectly typed. 主机名输入错误。

To find out the exact issue, I had to do the following in my console: 为了找出确切的问题,我必须在控制台中执行以下操作:

ping <host-name>

or if you have redis-cli installed, you can just call that from the console as such: 或者如果您已安装redis-cli,则可以从控制台这样调用它:

redis-cli -h <host-name> -p <port-number> -a <auth-pass>

Source 资源

For mac users: 对于Mac用户:

Open terminal and try this command: 打开终端并尝试以下命令:

  1. sudo vi /etc/hosts 须藤vi / etc / hosts
    (sudo to execute the command as a root user, You have enter the password for this) (以root用户身份执行命令的sudo,您已经为此输入了密码)
  2. press 'i' to get into input mode of VI editor 按'i'进入VI编辑器的输入模式
  3. Add this line at the end 127.0.0.1 redis 127.0.0.1 redis末尾添加此行
  4. press esc to go to command mode 按esc进入命令模式
  5. type :wq (to save and quit the vi 键入:wq(保存并退出vi
    editor) 编辑)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM