Re_Backend/monitoring/REDIS_MIGRATION.md

3.6 KiB

🔄 Redis Migration Guide

Overview

Redis is now part of the monitoring stack and running locally in Docker.


What Was Done

  1. Added Redis to monitoring stack

    • Image: redis:7-alpine
    • Container name: re_redis
    • Port: 6379 (mapped to host)
    • Password: Uses REDIS_PASSWORD from environment (default: Redis@123)
    • Data persistence: Volume re_redis_data
  2. Updated Redis Exporter

    • Now connects to local Redis container
    • Automatically starts after Redis is healthy

🔧 Update Backend Configuration

Step 1: Update .env file

Open Re_Backend/.env and change:

# OLD (External Redis)
REDIS_HOST=160.187.166.17

# NEW (Local Docker Redis)
REDIS_HOST=localhost

Or if you want to use Docker network (recommended for production):

REDIS_HOST=re_redis  # Use container name if backend is also in Docker

Step 2: Restart Backend

# Stop backend (Ctrl+C in terminal)
# Then restart
npm run dev

📊 Verify Everything Works

1. Check Redis is Running

docker ps --filter "name=redis"

Should show:

re_redis            Up (healthy)
re_redis_exporter   Up

2. Test Redis Connection

# Test from host
redis-cli -h localhost -p 6379 -a Redis@123 ping
# Should return: PONG

3. Check Backend Logs

[info]: [Redis] ✅ Connected successfully
[info]: [TAT Queue] ✅ Queue initialized
[info]: [Pause Resume Queue] ✅ Queue initialized

4. Refresh Grafana Dashboard


🎯 Benefits of Local Redis

Simpler Setup - Everything in one place
Faster Performance - Local network, no external latency
Data Persistence - Redis data saved in Docker volume
Easy Monitoring - Redis Exporter automatically connected
Environment Isolation - No conflicts with external Redis


🔄 Docker Commands

Start all monitoring services (including Redis)

cd Re_Backend/monitoring
docker-compose -f docker-compose.monitoring.yml up -d

Stop all services

docker-compose -f docker-compose.monitoring.yml down

View Redis logs

docker logs re_redis

Redis CLI access

docker exec -it re_redis redis-cli -a Redis@123

Check Redis data

# Inside redis-cli
INFO
DBSIZE
KEYS *

🗄️ Data Persistence

Redis data is persisted in Docker volume:

Volume: re_redis_data
Location: Docker managed volume

To backup Redis data:

docker exec re_redis redis-cli -a Redis@123 SAVE
docker cp re_redis:/data/dump.rdb ./redis-backup.rdb

⚠️ If You Want to Keep External Redis

If you prefer to keep using the external Redis server, simply:

  1. Update docker-compose.monitoring.yml:
redis-exporter:
  environment:
    - REDIS_ADDR=redis://160.187.166.17:6379
  command:
    - '--redis.addr=160.187.166.17:6379'
    - '--redis.password=Redis@123'
  1. Don't change .env in backend

  2. Remove the redis service from docker-compose if you don't need it locally


🎉 Summary

Your setup now includes:

  • Redis running locally in Docker
  • Redis Exporter connected and working
  • Backend ready to connect (just update REDIS_HOST=localhost in .env)
  • All monitoring metrics available in Grafana

Next step: Update Re_Backend/.env with REDIS_HOST=localhost and restart your backend!