Most webmasters and web hosts that use Redis would have seen this error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
It is usually caused when the Redis service is stopped in the server.
As part of our Server Management Services for online service providers and website owners, we have seen several other causes for this error.
Today we’ll go through the top causes and fixes for the Redis connection refused error.
What causes Redis connection refused error?
Redis is used by many to reduce application load time. However, users at times complain that they receive a connection refused error after installing the Redis extension.
The common reasons that trigger the error include:
- Redis-Server not Started
- Firewall Restriction
- Resource usage
Apart from these, there are some alternate reasons that trigger the Redis connection error. Today, let’s look into the reasons for could not connect to Redis connection refused error and its fixes.
Redis-Server is not started
The most common reason for the connection refused error is that the Redis-Server is not started.
Redis server should be started to use the Redis client after its installation. It can be done with the following command.
Also to run Redis in the background, following command could be used.
redis-server --daemonize yes
Firewall restriction is another common reason that can trigger the “could not connect to Redis connection refused”.
By default Redis server listen to the TCP port 6379. If another application is using the port or if the firewall restrictions blocks the port, it can trigger the connection refused error.
Thus it is important to check the status of the port in the firewall configuration while troubleshooting the could not connect to Redis error.
As we discussed earlier, Redis uses the main memory to store the data. Thus if the resource in the server is not sufficient for the process to run, it may get terminated abruptly.
When the status of the Redis process is down, it triggers the could not connect to Redis error. We could confirm if it actually running using the ps command.
ps -aux | grep redis
Our Support Engineers analyzes the Redis log file to confirm if the service is repeatedly flapping in the server. From a simultaneous analysis of other log files, we confirm if any other process is consuming resources in the server and is causing Redis to terminate.
Apart from the reasons mentioned above some settings in the Redis configuration file could also result in the connection failed error. The default location for the configuration file in Ubuntu 18 is /etc/redis/redis.conf.
Some of the reasons that may trigger the connection refused error include:
- The password set in the Redis configuration file. To fix it, comment the following line.
#requirepass <some pass if any>
- If the IP binding is not open for access from the internet in the config. Commenting the following lines will fix the issue.
# bind 127.0.0.1 ::1
[Are you struggling with Redis errors? We’ll fix it right away.]
In short, a number of reasons can trigger the Redis connection refused error. This ranges from firewall restrictions to resource limitations. Today we discussed how our Support Engineers fixes the error in each scenario.