5
votes

When I use redis PHP extension, I get the error, the host is 127.0.0.1 and the port is 6379.

Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known.

3
are you sure your redis is running on port 6379?Kasia Gogolek

3 Answers

2
votes

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. As a result, I had no IP assigned to 'localhost' name.

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').
  2. In your /etc/hosts file check that there's an IP assigned to that host name. (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.)

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.

1
votes

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 -h <host-name> -p <port-number> -a <auth-pass>

Source

1
votes

For mac users:

Open terminal and try this command:

  1. sudo vi /etc/hosts
    (sudo to execute the command as a root user, You have enter the password for this)
  2. press 'i' to get into input mode of VI editor
  3. Add this line at the end 127.0.0.1 redis
  4. press esc to go to command mode
  5. type :wq (to save and quit the vi
    editor)