How to fix Connection refused in Redis

RedisBEGINNERHIGHUpdated Dec 25, 2025ยท 347 views

Connection refused errors occur when your application cannot establish a TCP connection to the Redis server. This typically means Redis isn't running, is listening on a different port, or network/firewall rules are blocking the connection.

Quick fix

Fixes ECONNREFUSED

redis-cli ping
  1. Check if Redis is running
  2. Start Redis if it's not running
  3. Verify host and port configuration
  4. Check firewall rules
redis โ€” error
redis-cli ping
Connection refused

What this error means

The "Connection refused" error happens when your client attempts to connect to Redis on a specific host and port, but the operating system actively rejects the connection. This indicates that either: 1. The Redis server process is not running 2. Redis is not listening on the host/port your client expects 3. Network or firewall rules are blocking the connection 4. The Redis service has crashed or been terminated The error message typically includes the host and port, like "connect ECONNREFUSED 127.0.0.1:6379", making it clear exactly where the client was trying to connect.

Typical symptoms

  • Application fails to start with 'Connection refused' or 'ECONNREFUSED' error
  • Tests fail when they try to access Redis data
  • Error messages show the specific host:port that couldn't be reached (e.g., 127.0.0.1:6379)
  • Application works locally but fails in Docker or remote environments
  • Redis commands work with redis-cli but your application still can't connect

Common causes

  1. Redis server is not running or has crashed
  2. Wrong host or port configuration in your application
  3. Firewall blocking connections to the Redis port (default 6379)
  4. Redis bind address configuration mismatch (e.g., bound to localhost but client connects from different network)
  5. Another application already using the Redis port
  6. Redis protected-mode enabled without proper authentication setup
  7. Network connectivity issues between client and Redis server

How to fix "Connection refused"

1Check if Redis is running

Use the redis-cli ping command to verify the Redis server is responding:

bash
redis-cli ping

If Redis is running, you'll see "PONG" response. If you get a connection refused error, Redis is not running.

On Linux systems, you can also check the process:

bash
ps aux | grep redis-server
2Start Redis if it's not running

Use the appropriate command for your system:

Linux (systemd):

bash
sudo systemctl start redis-server

Linux (service command):

bash
sudo service redis-server start

macOS (Homebrew):

bash
brew services start redis

Manual start:

bash
redis-server

After starting, verify it's running with:

bash
redis-cli ping
3Verify host and port configuration

Check what host and port your application is trying to connect to. Look for Redis connection settings in your code or configuration files:

- Default host: 127.0.0.1 or localhost
- Default port: 6379

Make sure your application connects to the correct values. For Docker environments, use the Redis service name as the host (not localhost).

Test connectivity to the expected host/port using telnet:

bash
telnet localhost 6379

If connection succeeds, you'll see a prompt. If refused, Redis is not listening on that address.

4Check firewall rules

If connecting from a different machine, verify firewall allows port 6379.

On UFW (Ubuntu/Debian):

bash
sudo ufw allow 6379

Check current status:

bash
sudo ufw status

On iptables:

bash
sudo iptables -L | grep 6379

If the port is blocked, open it with:

bash
sudo iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
5Check Redis bind address configuration

Redis configuration controls which addresses it listens on. If Redis only binds to localhost (127.0.0.1) but your client is on a different network, you'll get connection refused.

Check the Redis configuration file (typically /etc/redis/redis.conf):

bash
grep '^bind' /etc/redis/redis.conf

- If it shows bind 127.0.0.1, Redis only accepts local connections
- For Docker or remote access, it should be bind 0.0.0.0

Edit the config file and change the bind address, then restart Redis:

bash
sudo systemctl restart redis-server
6Check for port conflicts

Verify another process isn't already using port 6379:

On Linux/macOS:

bash
lsof -i :6379

On Linux with netstat:

bash
netstat -an | grep 6379

If another process occupies the port, either:
1. Stop that process
2. Configure Redis to use a different port
3. Configure your application to connect to the other process's port if that's what you intended

Advanced notes

Docker Considerations: When running Redis in Docker and connecting from another container, use the Redis service name as the host (e.g., "redis" instead of "localhost"). Make sure containers are on the same network. If Redis is outside Docker, use the host's IP address (not localhost).

Protected Mode: Redis 6.0+ enables protected-mode by default, which requires either localhost connection or a password. If you're getting refused connections from remote machines even with the bind address set correctly, disable protected-mode in redis.conf or set a requirepass.

DNS Resolution: In some environments (Kubernetes, complex Docker setups), DNS resolution delays can cause timeouts that appear as connection refused. Ensure your client uses the correct hostname and allow sufficient connection timeout.

Cloud Deployments: On Railway, AWS ElastiCache, or other cloud Redis services, the host/port differ from local defaults. Always use the connection string provided by your cloud provider. Cloud firewalls may also require inbound rules.

Frequently asked questions

What does "ECONNREFUSED" mean?
The "Connection refused" error happens when your client attempts to connect to Redis on a specific host and port, but the operating system actively rejects the connection. This indicates that either: 1. The Redis server process is not running 2.
How do I fix "ECONNREFUSED"?
Connection refused errors occur when your application cannot establish a TCP connection to the Redis server. This typically means Redis isn't running, is listening on a different port, or network/firewall rules are blocking the connection.
What causes "ECONNREFUSED"?
Redis server is not running or has crashed Wrong host or port configuration in your application Firewall blocking connections to the Redis port (default 6379)
Is the "ECONNREFUSED" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading