Redis connection refused (Error: connect ECONNREFUSED 127.0.0.1:6379)

Redis Connection Refused: Could Not Connect to Redis

Redis won't connect because the server isn't running or the config is wrong. Here's exactly what to check.

Quick answer: Start Redis: sudo systemctl start redis or redis-server /etc/redis/redis.conf. If it still fails, check bind 127.0.0.1 and protected-mode yes in the config.

This error – Error: connect ECONNREFUSED 127.0.0.1:6379 – means your client sent a TCP handshake to Redis but got back a RST (reset) packet. The server isn't listening on that port. Usually that's because Redis isn't started, or it's started but bound to a different interface (like localhost only when you're connecting from the same box, or the reverse). I've seen this mostly on fresh Ubuntu 22.04 installs where Redis is installed but the systemd service is disabled. Also happens when you run multiple Redis instances and forget which port is which.

Fix Steps

  1. Check if Redis is running
    Run sudo systemctl status redis or ps aux | grep redis-server. If it's not there, start it: sudo systemctl start redis. For the background: systemd may be installed but the service unit file might be missing on some minimal Docker images – then use redis-server & to start it directly.
  2. Verify the port and bind address
    Open /etc/redis/redis.conf and look for bind and port. Default is bind 127.0.0.1 and port 6379. If you're connecting from the same machine, that's fine. But if you set bind 0.0.0.0 and still get refused, it's probably protected-mode. Also see if port is commented out – that'll make Redis use 0, meaning no TCP port.
  3. Disable protected mode for remote access
    If you need to connect from another host, set protected-mode no in the config. The reason: protected mode only allows connections from localhost if no password is set. Without this, Redis will reject remote connections even if bind 0.0.0.0.
  4. Restart Redis
    After any config change: sudo systemctl restart redis or redis-server /etc/redis/redis.conf. Verify with redis-cli ping – you should see PONG.
  5. Check firewall
    If connecting remotely, run sudo ufw status (or iptables -L). Port 6379 must be open. On a cloud server, also check the security group rules.

Alternative Fixes If the Main Steps Don't Work

  • Try a different client IP
    If you're connecting via a Docker container, use host.docker.internal on Mac/Windows or 172.17.0.1 on Linux. Reason: inside Docker, 127.0.0.1 is the container's own loopback, not the host's.
  • Manually start Redis in foreground
    Run redis-server --port 6379 --bind 0.0.0.0 directly in terminal. If it starts, the issue is with your config file or service unit. If it fails, you'll see the exact error message like Fatal error, can't open config file or Address already in use.
  • Kill stale Redis process
    Sometimes a zombie process holds the port. sudo lsof -i :6379 shows the PID. Then sudo kill -9 <PID> and restart.
  • Clear Redis socket file
    If you use Unix socket (path like /tmp/redis.sock), delete it manually: sudo rm /tmp/redis.sock. This helps when Redis crashes and leaves a stale socket.

Prevention Tip

Add a simple health check in your deployment script or cron job: redis-cli ping > /dev/null 2>&1 || systemctl restart redis. Also set logfile /var/log/redis/redis.log in config – when it fails again, check that log. The line # Server started, Redis version 7.2.4 confirms a clean start. If you see Can't bind: Address already in use, you've got a port conflict.

One more tip: always test the connection with redis-cli from the same machine your app runs on. That isolates network issues from config issues. I've spent hours debugging only to find the app was using a different Redis hostname than localhost.

Related Errors in Database Errors
2627 Fix 'Cannot insert duplicate key' in SQL Server fast Database View Definition Lost After Restore – Fix It Fast 0X0000041F Fix ERROR_SERVICE_DATABASE_LOCKED (0X0000041F) Fast SQL Server Network Interfaces: Error 26 – Error Locating Server/Instance Specifi Can't connect to SQL Server? Fix the database error fast

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.