Redis "Connection refused" on port 6379: how to fix it

Could not connect to Redis at 127.0.0.1:6379, ECONNREFUSED, Error 111: Redis is not running, listening elsewhere or unreachable from a container. Check each cause in order.

· 5 min read · By the Spot Downtime team

The message depends on the client, but the problem is the same:

text
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Error: connect ECONNREFUSED 127.0.0.1:6379
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

"Connection refused" means the machine at that address answered, but nothing was listening on that port. That rules out a lot: the network path works. Redis is either not running, listening on a different address or port, or you are connecting to the wrong machine. The general version of this error is in ERR_CONNECTION_REFUSED.

Refused or timed out?

If the connection hangs and then times out instead, the cause is different: a firewall or security group is dropping the packets. Refused means you reached the host and it said no.

Step 1: is Redis running?

bash
redis-cli ping            # PONG means it is up
sudo systemctl status redis-server   # Debian/Ubuntu (redis on RHEL/Fedora)
sudo journalctl -u redis-server --since "1 hour ago"

If it is stopped, the log usually says why. Common reasons:

  • Killed for memory. Redis holds everything in RAM. Without a maxmemory limit it can grow until the kernel kills it. Look for an OOM kill in dmesg, and see Linux out of memory.
  • Config error after an edit. Redis refuses to start on an unknown or invalid directive and logs the line number.
  • Cannot write its data directory. Wrong permissions on /var/lib/redis or a full disk. See no space left on device.

Step 2: what address and port is it on?

bash
sudo ss -ltnp | grep redis

Compare the output with what your app connects to. By default Redis listens on 127.0.0.1:6379 and [::1]:6379 only, set by bind in redis.conf. That causes two common mismatches:

  • The app runs on a different machine and connects to the server's IP, but Redis only listens on localhost. Change bind to include the private interface address, and set a password.
  • Redis runs on a non-default port, or there are several instances, and the app uses 6379.

With protected-mode yes (the default) and no password set, Redis also rejects clients that are not on localhost. That produces a DENIED error rather than a refusal, but it often shows up right after you fix bind.

Step 3: in Docker, localhost is the container

This is the most common cause in containerized apps. Inside a container, localhost means that container itself, not the host and not the Redis container next to it. Connect using the Compose service name instead:

yaml
services:
  app:
    environment:
      REDIS_URL: redis://redis:6379   # the service name, not localhost
    depends_on:
      redis:
        condition: service_healthy
  redis:
    image: redis:7
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s

The health check matters too. Without it, the app can start before Redis is ready, get refused on its first connection and crash. If the app container then restarts over and over, see Docker container keeps restarting.

Kubernetes

Connect to the Service name (redis.default.svc.cluster.local), and check that the Service selector matches the Redis pod's labels. A Service with no ready endpoints refuses connections.

  • ERR max number of clients reached: Redis is up but at maxclients (10000 by default). Usually a connection leak in the app.
  • MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk: a background save failed, often from a full disk or memory pressure, and Redis now rejects writes.
  • OOM command not allowed when used memory > 'maxmemory': the memory limit is reached and the eviction policy is noeviction.

Monitor Redis without exposing it

Redis should not be reachable from the public internet, so do not open 6379 just to monitor it. Instead, add a health endpoint to your app that runs PING against Redis and returns an error status if it fails, and point a website monitor at it. That catches a stopped Redis, a bad bind after a config change and a wrong hostname after a deploy, and it tests the path your app actually uses. If Redis runs on a host you manage, a server monitor shows the memory growth that usually comes before an OOM kill. For services that are meant to be reachable, a TCP port check catches refused connections directly.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading