← Back to all posts

Redis "Connection Refused" on localhost: The 6 Real Causes

Published October 2, 2026

⏱️ 3 min read

redis-cli ping answering Could not connect to Redis at 127.0.0.1:6379: Connection refused is a socket-level failure — nothing is listening where you are connecting, or a firewall dropped you. Work through these six causes in order.

1. Redis is simply not running

The obvious one first:

systemctl status redis-server   # or: redis-server --version

If it is dead, check journalctl -u redis-server -n 50 for why. The most common crash cause: the maxmemory setting is fine but the host has no memory at all and the OOM killer won. Check dmesg | grep -i kill.

2. It is listening on a different port

Configs drift. Confirm where Redis actually listens:

ss -ltnp | grep redis

If it shows 6380 (someone changed port in redis.conf), your tooling must match. A TLS-enabled Redis listens on 6379 still, but your client needs --tls.

3. It is bound to 127.0.0.1 but you are on IPv6 ::1

A sneaky one: the app resolves localhost to ::1, while Redis binds 127.0.0.1 only. Test explicitly:

redis-cli -h 127.0.0.1 ping

If that works but redis-cli -h localhost ping does not, your resolver order is the problem. Use the explicit address in app configs.

4. It is in a container, and localhost is the wrong localhost

From inside the container, localhost means the container. From the host, localhost means the host. If Redis runs in Docker with the default bridge, either publish the port (-p 6379:6379) or put the app in the same compose network and address it by service name (redis:6379). This is the same class of mistake as every other Docker Compose "connection refused" — localhost lies about where it points.

5. Protected mode is not the cause — a firewall is

Protected mode returns a different error (DENIED, not refused). Refused means the TCP handshake failed. On the same host, check local rules:

sudo iptables -L -n | head -20   # or: sudo nft list ruleset | head

Cloud hosts: the security group must allow the port — but for localhost connections it should not matter unless you use the public IP from the same box.

6. Unix socket mode

If redis.conf sets unixsocket /tmp/redis.sock and port 0, there is no TCP listener at all. Connect with redis-cli -s /tmp/redis.sock.

Confirm each cause in one pass

systemctl status redis-server; ss -ltnp | grep redis; redis-cli -h 127.0.0.1 ping

That trio answers running?, listening where?, reachable? — 90% of refusals end there.

If Redis keeps dying from memory pressure, moving it to a small dedicated VM is often cheaper than debugging a noisy neighbor — see our budget cloud pick (partner link) for right-sized instances.

Partner pick — sponsored

Sentry — our error-tracking pick for this stack

See the exact line of code that broke — before your users report it. Free tier for small teams.

Get Sentry →
Also vetted

Vultr — Spin a disposable box to replay this failure without touching prod.

Get Vultr →

We earn a commission if you buy through our links — it never costs you extra. More vetted tools on our picks hub · comparing clouds? DigitalOcean vs Vultr and vs AWS · full deals: DigitalOcean · Vultr · NordLayer · Semrush

#AmazonAssociate — As an Amazon Associate I earn from qualifying purchases. Full disclosure →