Re_Backend/docs/REDIS_SETUP_WINDOWS.md

325 lines
7.9 KiB
Markdown

# Redis Setup for Windows
## ⚠️ IMPORTANT: Redis Version Requirements
**BullMQ requires Redis version 5.0.0 or higher.**
**DO NOT USE**: Microsoft Archive Redis (https://github.com/microsoftarchive/redis/releases)
- This is **outdated** and only provides Redis 3.x
- **Version 3.0.504 is NOT compatible** with BullMQ
- You will get errors: `Redis version needs to be greater or equal than 5.0.0`
**USE ONE OF THESE METHODS INSTEAD**:
---
## Method 1: Using Memurai (Recommended for Windows) ⭐
Memurai is a **Redis-compatible** server built specifically for Windows with full Redis 6.x+ compatibility.
### Why Memurai?
-**Native Windows support** - Runs as a Windows service
-**Redis 6.x+ compatible** - Full feature support
-**Easy installation** - Just install and run
-**Free for development** - Free tier available
-**Production-ready** - Used in enterprise environments
### Installation Steps:
1. **Download Memurai**:
- Visit: https://www.memurai.com/get-memurai
- Download the **Developer Edition** (free)
2. **Install**:
- Run the installer (`Memurai-*.exe`)
- Choose default options
- Memurai will install as a Windows service and start automatically
3. **Verify Installation**:
```powershell
# Check if service is running
Get-Service Memurai
# Should show: Running
# Test connection
memurai-cli ping
# Should return: PONG
# Check version (should be 6.x or 7.x)
memurai-cli --version
```
4. **Configuration**:
- Default port: **6379**
- Connection string: `redis://localhost:6379`
- Service runs automatically on Windows startup
- No additional configuration needed for development
## Method 2: Using Docker Desktop (Alternative) 🐳
If you have Docker Desktop installed, this is the easiest method to get Redis 7.x.
### Installation Steps:
1. **Install Docker Desktop** (if not already installed):
- Download from: https://www.docker.com/products/docker-desktop
- Install and start Docker Desktop
2. **Start Redis Container**:
```powershell
# Run Redis 7.x in a container
docker run -d --name redis-tat -p 6379:6379 redis:7-alpine
# Or if you want it to restart automatically:
docker run -d --name redis-tat -p 6379:6379 --restart unless-stopped redis:7-alpine
```
3. **Verify**:
```powershell
# Check if container is running
docker ps | Select-String redis
# Check Redis version
docker exec redis-tat redis-server --version
# Should show: Redis server v=7.x.x
# Test connection
docker exec redis-tat redis-cli ping
# Should return: PONG
```
4. **Stop/Start Redis**:
```powershell
# Stop Redis
docker stop redis-tat
# Start Redis
docker start redis-tat
# Remove container (if needed)
docker rm -f redis-tat
```
## Method 3: Using WSL2 (Windows Subsystem for Linux)
1. **Enable WSL2**:
```powershell
wsl --install
```
2. **Install Redis in WSL**:
```bash
sudo apt update
sudo apt install redis-server
sudo service redis-server start
```
3. **Verify**:
```bash
redis-cli ping
# Should return: PONG
```
## Quick Test
After starting Redis, test the connection:
```powershell
# If you have redis-cli or memurai-cli
redis-cli ping
# Or use telnet
Test-NetConnection -ComputerName localhost -Port 6379
```
## Troubleshooting
### ❌ Error: "Redis version needs to be greater or equal than 5.0.0 Current: 3.0.504"
**Problem**: You're using Microsoft Archive Redis (version 3.x) which is **too old** for BullMQ.
**Solution**:
1. **Stop the old Redis**:
```powershell
# Find and stop the old Redis process
Get-Process redis-server -ErrorAction SilentlyStop | Stop-Process -Force
```
2. **Uninstall/Remove old Redis** (if installed as service):
```powershell
# Check if running as service
Get-Service | Where-Object {$_.Name -like "*redis*"}
```
3. **Install one of the recommended methods**:
- **Option A**: Install Memurai (Recommended) - See Method 1 above
- **Option B**: Use Docker - See Method 2 above
- **Option C**: Use WSL2 - See Method 3 above
4. **Verify new Redis version**:
```powershell
# For Memurai
memurai-cli --version
# Should show: 6.x or 7.x
# For Docker
docker exec redis-tat redis-server --version
# Should show: Redis server v=7.x.x
```
5. **Restart your backend server**:
```powershell
# The TAT worker will now detect the correct Redis version
npm run dev
```
### Port Already in Use
```powershell
# Check what's using port 6379
netstat -ano | findstr :6379
# Kill the process if needed (replace <PID> with actual process ID)
taskkill /PID <PID> /F
# Or if using old Redis, stop it:
Get-Process redis-server -ErrorAction SilentlyStop | Stop-Process -Force
```
### Service Not Starting (Memurai)
```powershell
# Start Memurai service
net start Memurai
# Check service status
Get-Service Memurai
# Check logs
Get-EventLog -LogName Application -Source Memurai -Newest 10
# Restart service
Restart-Service Memurai
```
### Docker Container Not Starting
```powershell
# Check Docker is running
docker ps
# Check Redis container logs
docker logs redis-tat
# Restart container
docker restart redis-tat
# Remove and recreate if needed
docker rm -f redis-tat
docker run -d --name redis-tat -p 6379:6379 redis:7-alpine
```
### Cannot Connect to Redis
```powershell
# Test connection
Test-NetConnection -ComputerName localhost -Port 6379
# For Memurai
memurai-cli ping
# For Docker
docker exec redis-tat redis-cli ping
```
## Configuration
### Environment Variable
Add to your `.env` file:
```env
REDIS_URL=redis://localhost:6379
```
### Default Settings
- **Port**: `6379`
- **Host**: `localhost`
- **Connection String**: `redis://localhost:6379`
- No authentication required for local development
- Default configuration works out of the box
## Verification After Setup
After installing Redis, verify it's working:
```powershell
# 1. Check Redis version (must be 5.0+)
# For Memurai:
memurai-cli --version
# For Docker:
docker exec redis-tat redis-server --version
# 2. Test connection
# For Memurai:
memurai-cli ping
# Expected: PONG
# For Docker:
docker exec redis-tat redis-cli ping
# Expected: PONG
# 3. Check if backend can connect
# Start your backend server and check logs:
npm run dev
# Look for:
# [TAT Queue] Connected to Redis
# [TAT Worker] Connected to Redis at redis://127.0.0.1:6379
# [TAT Worker] Redis version: 7.x.x (or 6.x.x)
# [TAT Worker] Worker is ready and listening for jobs
```
## Quick Fix: Migrating from Old Redis
If you already installed Microsoft Archive Redis (3.x), follow these steps:
1. **Stop old Redis**:
```powershell
# Close the PowerShell window running redis-server.exe
# Or kill the process:
Get-Process redis-server -ErrorAction SilentlyStop | Stop-Process -Force
```
2. **Choose a new method** (recommended: Memurai or Docker)
3. **Install and verify** (see methods above)
4. **Update .env** (if needed):
```env
REDIS_URL=redis://localhost:6379
```
5. **Restart backend**:
```powershell
npm run dev
```
## Production Considerations
- ✅ Use Redis authentication in production
- ✅ Configure persistence (RDB/AOF)
- ✅ Set up monitoring and alerts
- ✅ Consider Redis Cluster for high availability
- ✅ Use managed Redis service (Redis Cloud, AWS ElastiCache, etc.)
---
## Summary: Recommended Setup for Windows
| Method | Ease of Setup | Performance | Recommended For |
|--------|---------------|-------------|-----------------|
| **Memurai** ⭐ | ⭐⭐⭐⭐⭐ Very Easy | ⭐⭐⭐⭐⭐ Excellent | **Most Users** |
| **Docker** | ⭐⭐⭐⭐ Easy | ⭐⭐⭐⭐⭐ Excellent | Docker Users |
| **WSL2** | ⭐⭐⭐ Moderate | ⭐⭐⭐⭐⭐ Excellent | Linux Users |
| ❌ **Microsoft Archive Redis** | ❌ Don't Use | ❌ Too Old | **None - Outdated** |
**⭐ Recommended**: **Memurai** for easiest Windows-native setup, or **Docker** if you already use Docker Desktop.