How to Fix Redis Connection Refused
Redis returns 'connection refused' when it's bound to an interface the client can't reach - not because the process is down. The most common cause is a bind address mismatch in redis.conf. Here's how to find it and fix it.
Why the connection is refused (not why Redis is down)
redis-cli ping returning Could not connect to Redis at 127.0.0.1:6379: Connection refused
does not mean Redis crashed. It means Redis is listening on a different interface than the
one you're dialing. The process is up; the bind address is wrong.
Check what address Redis is actually listening on:
ss -tlnp | grep 6379
If you see 10.0.0.1:6379 instead of 127.0.0.1:6379 or 0.0.0.0:6379, that's your
problem. The bind directive in redis.conf was changed and no longer includes the loopback.
The bind directive in redis.conf
Redis only listens on the addresses listed in bind. The default is:
bind 127.0.0.1 -::1
A common misconfiguration replaces the loopback with a private IP:
# wrong - client connecting from localhost can't reach this
bind 10.0.0.1
To restore local connectivity, change the bind address back to include 127.0.0.1:
# /etc/redis/redis.conf
bind 127.0.0.1
Then restart Redis to apply the change:
service redis-server restart
redis-cli ping # should return PONG
Verify with ss and redis-cli
After restarting, confirm Redis is on the right interface:
ss -tlnp | grep 6379 # should show 127.0.0.1:6379
redis-cli ping # PONG
redis-cli -h 127.0.0.1 ping # PONG
Then confirm your application can connect. If it's a Flask app using Redis as a cache, a quick check is:
curl http://localhost:5000/health
A 200 response means the caching layer is back up.
Security note: bind and authentication
Redis defaults to 127.0.0.1 for a reason - it's only reachable from processes on the same
host. If you need Redis reachable from other hosts, bind it to the right private IP and
set requirepass in redis.conf plus a firewall rule. Historically, exposed Redis instances
with no auth have been mass-exploited by worms scanning for open port 6379.
For single-server setups (app and Redis on the same host), bind 127.0.0.1 is both secure
and sufficient.
Want to try it hands-on? HeyDevJob gives you this exact setup in a live cloud workspace in your browser - edit it, run it, and see it work. Free, nothing to install.
Try it in a workspace →What you'll practice
- Using ss -tlnp to find what interface Redis is actually listening on
- Editing the bind directive in /etc/redis/redis.conf and restarting safely
- Verifying app connectivity after restoring the Redis bind address
FAQ
Why does Redis say connection refused if the process is running?
Redis binds only to the addresses listed in the 'bind' directive. If that's set to a private IP like 10.0.0.1 instead of 127.0.0.1, a client connecting via localhost will get connection refused even though the Redis process is running. Use ss -tlnp | grep 6379 to see what interface Redis is actually on.
How do I fix Redis connection refused on 127.0.0.1:6379?
Open /etc/redis/redis.conf and set bind 127.0.0.1. Restart Redis with service redis-server restart, then verify with redis-cli ping - you should get PONG.
Is it safe to set Redis bind to 0.0.0.0?
Only if Redis is behind a firewall and has requirepass set. Binding to 0.0.0.0 makes Redis reachable on every interface including external ones. For a single-server setup where the app and Redis are on the same host, 127.0.0.1 is safer and sufficient.
How do I fix a Redis connection refused error?
Connection refused means nothing is listening at that host and port. Check Redis is running, confirm the bind directive includes the interface you connect from (not just 127.0.0.1), check the port, and make sure no firewall blocks it - then restart Redis.
Keep learning
Learn it by doing. Open this in a live cloud workspace, make the change yourself, and keep a record of the work you can share.
Open the workspace →