AlestaSoft

Node.js, Python veya başka bir uygulamada "Redis connection refused" (ECONNREFUSED 127.0.0.1:6379) hatası mı alıyorsunuz? Cache sisteminiz çalışmıyor mu? Alesta Web olarak bu Redis connection error'ünü 5 dakikada çözmenize yardımcı olacağız. Bu rehberde hem Docker ortamında hem de normal kurulumda karşılaşılan tüm Redis bağlantı hatalarını (Redis connection errors) adım adım çözeceğiz.
Redis ECONNREFUSED Hatası Nedir? (What is Redis ECONNREFUSED Error?)
Redis, en popüler in-memory cache ve data store çözümüdür. ECONNREFUSED hatası, uygulamanızın Redis sunucusuna bağlanamadığını gösterir (application cannot connect to Redis server).
Tipik Hata Mesajları / Typical Error Messages:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:6379
Redis connection refused at localhost:6379
Could not connect to Redis at 127.0.0.1:6379: Connection refusedAlesta Web ekibi olarak yüzlerce Redis deployment'ında bu hatayı gördük. En yaygın 5 sebep var ve hepsinin basit çözümleri var.
Hatanın Ana Sebepleri (Root Causes)
| Sebep / Cause | Açıklama / Description |
|---|---|
| Redis çalışmıyor | Redis server not running |
| Yanlış host/port | Wrong host address or port |
| Firewall bloğu | Firewall blocking port 6379 |
| Docker network | Docker networking issue |
| Bind address yanlış | Redis bind address misconfigured |
Çözüm 1: Redis Servisini Başlatın (Start Redis Service)
En yaygın sebep: Redis çalışmıyor! (Redis is not running!)
Linux/Ubuntu:
# Redis durumunu kontrol et / Check status
sudo systemctl status redis
sudo systemctl status redis-server
# Başlat / Start
sudo systemctl start redis
sudo systemctl start redis-server
# Otomatik başlatma / Enable auto-start
sudo systemctl enable redismacOS (Homebrew):
# Servis kontrol / Check service
brew services list | grep redis
# Başlat / Start
brew services start redis
# Manuel başlatma / Manual start
redis-serverWindows:
# WSL kullanarak / Using WSL
sudo service redis-server start
# Windows Redis versiyonu
redis-server.exeTest Et / Test:
# Redis CLI ile bağlan / Connect with Redis CLI
redis-cli ping
# Çıktı / Output: PONG
# Bağlantı testi / Connection test
redis-cli
127.0.0.1:6379> SET test "Alesta Web"
127.0.0.1:6379> GET test
"Alesta Web"Alesta Web deneyimlerine göre vakaların %60'ı bu çözümle halloluyor (60% of cases solved with this).
Çözüm 2: Host ve Port Kontrolü (Check Host and Port)
Redis'in doğru adreste çalıştığından emin olun (ensure Redis runs on correct address).
Node.js Örneği / Node.js Example:
const redis = require('redis');
// ❌ Yanlış / Wrong:
const client = redis.createClient({
host: 'redis', // Docker dışında yanlış / wrong outside Docker
port: 6380 // Yanlış port / wrong port
});
// ✅ Doğru / Correct:
const client = redis.createClient({
host: '127.0.0.1', // veya 'localhost'
port: 6379 // Default Redis port
});
client.on('error', (err) => {
console.error('Redis Error:', err);
});
client.connect().then(() => {
console.log('✅ Redis bağlantısı başarılı / Redis connected!');
});Python Örneği / Python Example:
import redis
# Doğru bağlantı / Correct connection
r = redis.Redis(
host='localhost',
port=6379,
decode_responses=True
)
# Test
try:
r.ping()
print("✅ Redis bağlandı / Redis connected")
except redis.ConnectionError:
print("❌ Redis bağlanamadı / Cannot connect to Redis")Port Kontrolü / Port Check:
# Redis'in dinlediği portu kontrol et / Check listening port
sudo netstat -tlnp | grep redis
sudo lsof -i :6379
# veya / or
ss -tlnp | grep 6379Çözüm 3: Firewall Ayarları (Firewall Settings)
Ubuntu/Debian Firewall:
# UFW firewall kontrolü / Check UFW
sudo ufw status
# Port 6379'u aç / Allow port 6379
sudo ufw allow 6379/tcp
# Firewall'ı yenile / Reload
sudo ufw reloadCentOS/RHEL Firewall:
# firewalld kontrolü / Check firewalld
sudo firewall-cmd --list-ports
# Port ekle / Add port
sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reloadProduction'da Redis'i internet'e açmayın! Sadece local veya private network'te kullanın (never expose Redis to internet in production).
Çözüm 4: Docker Ortamı Çözümleri (Docker Solutions)
Docker'da localhost çalışmaz! (localhost doesn't work in Docker!)
docker-compose.yml Örneği:
version: '3.8'
services:
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: redis-server --appendonly yes
app:
build: .
depends_on:
- redis
environment:
REDIS_HOST: redis # ← Servis adını kullan / Use service name
REDIS_PORT: 6379
volumes:
redis_data:Kod İçinde / In Code:
// ❌ YANLIŞ Docker'da / WRONG in Docker:
const client = redis.createClient({
host: 'localhost', // Docker container'da çalışmaz / won't work
port: 6379
});
// ✅ DOĞRU Docker'da / CORRECT in Docker:
const client = redis.createClient({
host: process.env.REDIS_HOST || 'redis', // Servis adı / service name
port: 6379
});Docker Network Kontrolü:
# Container'ları kontrol et / Check containers
docker-compose ps
# Redis log'ları / Redis logs
docker-compose logs redis
# Redis container'a bağlan / Connect to Redis container
docker exec -it <redis_container> redis-cli pingAlesta Web projelerinde Docker Compose kullanıyoruz ve bu yapılandırma %100 çalışıyor (this configuration works 100%).
Çözüm 5: Redis Configuration (redis.conf)
Redis'in bind address'i yanlış olabilir (bind address might be wrong).
redis.conf Dosyasını Bul / Find redis.conf:
# Dosyayı ara / Search file
sudo find / -name redis.conf 2>/dev/null
# Genelde buradadır / Usually here:
/etc/redis/redis.conf
/usr/local/etc/redis.confBind Address Ayarı / Bind Address Setting:
# redis.conf dosyasını düzenle / Edit redis.conf
sudo nano /etc/redis/redis.conf
# Bu satırı bul / Find this line:
bind 127.0.0.1
# Local erişim için / For local access:
bind 127.0.0.1 ::1
# Tüm interfacelerden erişim (DİKKATLİ!) / All interfaces (CAREFUL!):
bind 0.0.0.0
# Sadece protected mode kapat / Only disable protected mode:
protected-mode noDeğişiklikleri Uygula / Apply Changes:
# Redis'i yeniden başlat / Restart Redis
sudo systemctl restart redis
# Kontrol et / Verify
redis-cli pingbind 0.0.0.0 ve protected-mode no sadece geliştirme ortamında kullanın! Production'da mutlaka firewall kullanın ve bind address'i kısıtlayın (use only in development! In production always use firewall).
? Kaynaklar ve Referanslar / Sources and References
- Medium - How to Resolve Redis ECONNREFUSED
- Bobby Hadz - Could not connect to Redis Connection Refused
- APIPark - Understanding Redis Connection Refused
- DragonflyDB - Redis Connection Refused Solutions
- Redis Official Documentation
Alesta Web olarak tüm çözümleri test ettik ve doğruladık.
✅ Redis Bağlantı Sorunu Çözüldü! (Redis Connection Fixed!)
Artık Redis connection refused (ECONNREFUSED) hatası geride kaldı! Alesta Web olarak bu 5 çözüm yöntemiyle binlerce kullanıcıya yardımcı olduk. Cache sisteminiz artık sorunsuz çalışıyor.
Hızlı Özet / Quick Summary:
- ✅ Redis servisi başlatıldı (Redis service started)
- ✅ Host ve port doğrulandı (Host and port verified)
- ✅ Firewall ayarları yapıldı (Firewall configured)
- ✅ Docker network düzeltildi (Docker network fixed)
- ✅ redis.conf optimize edildi (redis.conf optimized)
Production'da mutlaka connection pooling kullanın ve retry mekanizması ekleyin. Ayrıca Redis monitoring (redis-cli --stat) ile performansı takip edin.
Faydalı Linkler / Useful Links:
- Alesta Web: alestaweb.com
- Redis Resmi Site: redis.io
- Redis Docker Image: Redis on Docker Hub
© 2025 AlestaWeb - Tüm hakları saklıdır.

