Fix "Redis connection refused 127.0.0.1:6379" Error

Getting the "Redis connection refused 127.0.0.1:6379" error in your Node.js, Python, or Java application? This complete guide shows you how to start Redis server and fix connection issues on Windows, macOS, and Linux.

Redis Node.js Python Java Express Django

What This Error Looks Like

Node.js / ioredis Error:
Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)

Unhandled error event: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Node.js / redis (node-redis) Error:
[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)

Error: Redis connection failed: ECONNREFUSED 127.0.0.1:6379
Python / redis-py Error:
redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused.

Traceback (most recent call last):
  File "app.py", line 5, in 
    r = redis.Redis(host='localhost', port=6379)
redis.exceptions.ConnectionError: Connection refused
Java / Jedis Error:
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)

Quick Fix (Choose Your Operating System)

The Problem: Redis server is not running on port 6379

  1. Open Command Prompt
  2. Start Redis: redis-server
  3. Verify: redis-cli ping (should return PONG)
  4. Test your application again
  1. Open Terminal
  2. Start Redis: brew services start redis
  3. Verify: redis-cli ping (should return PONG)
  4. Test your application again
  1. Open Terminal
  2. Start Redis: sudo systemctl start redis
  3. Verify: redis-cli ping (should return PONG)
  4. Test your application again

Complete Troubleshooting Guide

1 Understand the Error

ECONNREFUSED on port 6379 means:

  • Redis server is not running (most common - 95% of cases)
  • Redis is running on a different port
  • Redis is bound to a different IP address
  • Firewall is blocking port 6379
  • Redis protected mode is blocking connections
Key Point: Port 6379 is Redis's default port. If nothing responds on this port, your application cannot connect.

2 Check if Redis is Running

Check Redis Status on Windows

cmd
# Method 1: Check if Redis process is running
tasklist | findstr redis

# Method 2: Check if port 6379 is listening
netstat -an | findstr :6379

# Method 3: Try connecting with redis-cli
redis-cli ping

Expected Output if Running:

redis-server.exe      5432 Console                    1     45,678 K
TCP    0.0.0.0:6379           0.0.0.0:0              LISTENING
PONG

Check Redis Status on macOS

bash
# Method 1: Using Homebrew services
brew services list | grep redis

# Method 2: Check process
ps aux | grep redis-server

# Method 3: Check if port 6379 is listening
lsof -i :6379

# Method 4: Try connecting
redis-cli ping

Expected Output if Running:

redis        started username ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
redis-ser 12345 user    6u  IPv4 0x... TCP localhost:6379 (LISTEN)
PONG

Check Redis Status on Linux

bash
# Method 1: Using systemctl
sudo systemctl status redis

# Method 2: Check process
ps aux | grep redis-server

# Method 3: Check if port 6379 is listening
sudo lsof -i :6379
# or
sudo netstat -tulpn | grep :6379

# Method 4: Try connecting
redis-cli ping

Expected Output if Running:

● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled)
   Active: active (running) since Mon 2024-01-15 10:30:00 UTC

PONG

3 Start Redis Server

Start Redis on Windows

Method 1: Manual Start (Foreground)

cmd
# Navigate to Redis directory (adjust path)
cd C:\Program Files\Redis

# Start Redis server
redis-server

# Or specify config file
redis-server redis.windows.conf

Method 2: Install as Windows Service

cmd
# Run as Administrator
cd C:\Program Files\Redis

# Install Redis as service
redis-server --service-install redis.windows.conf

# Start the service
redis-server --service-start

# Check service status
sc query Redis
Windows Note: If Redis is not installed, download from GitHub Redis for Windows or use WSL2 with Linux version.

Start Redis on macOS

Method 1: Using Homebrew Services (Recommended)

bash
# Start Redis and run at login (persistent)
brew services start redis

# Or just start once (stops on logout/restart)
brew services run redis

# Check status
brew services list

Method 2: Manual Start (Foreground)

bash
# Start Redis manually (runs in foreground)
redis-server

# Or with config file
redis-server /opt/homebrew/etc/redis.conf
If Redis isn't installed:
# Install Redis via Homebrew
brew install redis

# Then start it
brew services start redis

Start Redis on Linux

Using systemctl (Ubuntu/Debian/CentOS/RHEL)

bash
# Start Redis
sudo systemctl start redis

# Enable auto-start on boot
sudo systemctl enable redis

# Check status
sudo systemctl status redis

# Restart Redis
sudo systemctl restart redis

Manual Start (if systemctl not available)

bash
# Start Redis manually
redis-server

# Or with config file
redis-server /etc/redis/redis.conf
If Redis is not installed:
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install redis-server

# CentOS/RHEL
sudo yum install redis

# Then start it
sudo systemctl start redis

4 Verify Redis is Listening on Port 6379

After starting Redis, confirm it's actually listening on port 6379.

bash
# Windows
netstat -an | findstr :6379

# macOS/Linux
lsof -i :6379
# or
netstat -an | grep 6379

Expected Output:

# You should see Redis listening on 6379:
TCP    0.0.0.0:6379         0.0.0.0:0              LISTENING
TCP    [::]:6379            [::]:0                 LISTENING

# Or with lsof:
redis-ser 12345 user   6u  IPv4 0x... TCP localhost:6379 (LISTEN)
If you don't see port 6379: Redis is configured to use a different port. Check /etc/redis/redis.conf (Linux), /opt/homebrew/etc/redis.conf (macOS), or redis.windows.conf for the port setting.

5 Test Redis Connection

Using redis-cli

bash
# Test basic connection
redis-cli ping

# Should return: PONG

# Connect to Redis CLI
redis-cli

# Try some commands
> SET test "hello"
> GET test
> QUIT

Test from Your Application

Node.js / ioredis:

javascript
const Redis = require('ioredis');

const redis = new Redis({
  host: 'localhost',
  port: 6379,
  // password: 'yourpassword', // if required
});

redis.ping()
  .then(() => console.log('✓ Redis connected successfully'))
  .catch(err => console.error('✗ Redis connection error:', err.message));

Node.js / node-redis (v4+):

javascript
const redis = require('redis');

const client = redis.createClient({
  socket: {
    host: 'localhost',
    port: 6379
  }
});

client.connect()
  .then(() => client.ping())
  .then(() => console.log('✓ Redis connected successfully'))
  .catch(err => console.error('✗ Redis connection error:', err.message));

Python / redis-py:

python
import redis

try:
    r = redis.Redis(
        host='localhost',
        port=6379,
        # password='yourpassword',  # if required
        decode_responses=True
    )
    r.ping()
    print('✓ Redis connected successfully')
except Exception as e:
    print(f'✗ Redis connection error: {e}')

6 Configure Redis (If Needed)

Check Redis configuration file for connection settings.

bash
# Find redis.conf location:
# Linux: /etc/redis/redis.conf
# macOS: /opt/homebrew/etc/redis.conf
# Windows: C:\Program Files\Redis\redis.windows.conf

# Important settings to check:
bind 127.0.0.1      # Allow connections from localhost
port 6379           # Default Redis port
protected-mode yes  # Enable protected mode (requires password or bind)
Protected Mode: By default, Redis enables protected mode which only allows connections from localhost. If your app runs in Docker or a different machine, you need to either:
  • Set protected-mode no (not recommended for production)
  • Configure a password: requirepass yourpassword
  • Update bind directive to allow specific IPs

Common Issues and Solutions

Issue 1: redis-cli Works But Application Doesn't

Symptoms: redis-cli ping works, but your app gets connection refused

Cause: Application is trying to connect from different host or protected mode is enabled

Solutions:

bash
# Check Redis bind address
grep bind /etc/redis/redis.conf

# If it shows: bind 127.0.0.1
# This means Redis only accepts local connections

# Solution 1: Disable protected mode (development only)
# Edit redis.conf:
protected-mode no

# Solution 2: Set password (recommended)
requirepass yourpassword

# Then restart Redis
sudo systemctl restart redis

Issue 2: Redis Running on Different Port

Check which port Redis is actually using:

bash
# Check redis.conf for port setting
grep port /etc/redis/redis.conf

# Check which ports Redis is listening on
sudo lsof -i -P | grep redis
# or
sudo netstat -tulpn | grep redis

If Redis is on a different port, update your connection string to match.

Issue 3: Firewall Blocking Port 6379

Allow port 6379 through firewall:

bash
# Windows - Allow port 6379
netsh advfirewall firewall add rule name="Redis" dir=in action=allow protocol=TCP localport=6379

# Linux (Ubuntu/Debian) - Allow port 6379
sudo ufw allow 6379/tcp

# macOS - Check firewall settings
# System Preferences → Security & Privacy → Firewall

Issue 4: Redis in Docker Container

If using Redis in Docker:

bash
# Check if Redis container is running
docker ps | grep redis

# If not running, start it
docker start redis-container

# Or run a new Redis container
docker run -d -p 6379:6379 --name redis redis:latest

# Check container logs
docker logs redis-container

# Connect to Redis in Docker
docker exec -it redis-container redis-cli

Docker Compose example:

yaml
version: '3.8'
services:
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
    restart: always
    volumes:
      - redis-data:/data

volumes:
  redis-data:

Quick Reference Commands

cheatsheet
REDIS SERVICE COMMANDS BY OS
============================

Windows:
  Check:   tasklist | findstr redis
  Start:   redis-server
  Service: redis-server --service-start
  CLI:     redis-cli

macOS (Homebrew):
  Check:   brew services list | grep redis
  Start:   brew services start redis
  Stop:    brew services stop redis
  Restart: brew services restart redis

Linux (systemd):
  Check:   sudo systemctl status redis
  Start:   sudo systemctl start redis
  Stop:    sudo systemctl stop redis
  Enable:  sudo systemctl enable redis
  Restart: sudo systemctl restart redis

VERIFY REDIS
============
  Port check:     lsof -i :6379 (Mac/Linux) | netstat -an | findstr :6379 (Win)
  Test connect:   redis-cli ping (should return PONG)
  Connection URL: redis://localhost:6379

Still Having Issues?

Debugging checklist:

Visit our Interactive Diagnostic Wizard for personalized help.