Spaces:
Runtime error
Runtime error
Redis Setup Guide for Chat Agent
Why Redis is Used
The chat agent uses Redis for several performance and scalability benefits:
- Session Caching - Fast access to frequently used session data
- Chat History Caching - Quick retrieval of recent messages
- Rate Limiting - Distributed rate limiting across multiple app instances
- User Session Tracking - Managing multiple sessions per user
Error 10061 Explanation
Error 10061 connecting to localhost:6379 means:
- Port 6379 is Redis's default port
- No Redis server is running on your machine
- The application can't connect to Redis for caching
Installation Options
Option 1: Windows Native Installation
Download Redis for Windows:
- Visit: https://github.com/microsoftarchive/redis/releases
- Download the latest
.msiinstaller - Run the installer and follow the setup wizard
Start Redis:
# Redis should start automatically after installation # Or manually start it: redis-serverVerify Installation:
redis-cli ping # Should return: PONG
Option 2: Using Chocolatey (Windows)
# Install Chocolatey first if you don't have it
# Then install Redis:
choco install redis-64
# Start Redis
redis-server
# Test connection
redis-cli ping
Option 3: Using Docker (Recommended)
# Pull and run Redis container
docker run -d -p 6379:6379 --name redis redis:alpine
# Verify it's running
docker ps
# Test connection
docker exec -it redis redis-cli ping
Option 4: WSL/Linux
# Update package list
sudo apt update
# Install Redis
sudo apt install redis-server
# Start Redis service
sudo systemctl start redis-server
# Enable auto-start on boot
sudo systemctl enable redis-server
# Test connection
redis-cli ping
Configuration
Environment Variables
Create a .env file in your project root:
# Redis Configuration
REDIS_URL=redis://localhost:6379/0
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=
# For production with password:
# REDIS_URL=redis://:password@localhost:6379/0
# REDIS_PASSWORD=your-secure-password
Testing Configuration
For testing without Redis, set:
REDIS_URL=None
Or use the testing configuration which automatically disables Redis.
Running Without Redis
The application is designed to work without Redis, but with reduced performance:
What Works Without Redis:
- ✅ All API endpoints function normally
- ✅ Session management (database-only)
- ✅ Chat history (database-only)
- ✅ Language context management
- ✅ Authentication and authorization
What's Affected Without Redis:
- ⚠️ Performance: Slower session and message retrieval
- ⚠️ Rate Limiting: Uses in-memory storage (not distributed)
- ⚠️ Caching: No caching layer, all requests hit the database
- ⚠️ Scalability: Cannot scale across multiple app instances
Performance Impact:
- Session retrieval: ~50-100ms slower per request
- Chat history: ~100-200ms slower for large histories
- Rate limiting: Resets when app restarts
Production Recommendations
Redis Configuration for Production:
- Use a dedicated Redis instance
- Enable password authentication
- Configure persistence (RDB + AOF)
- Set up monitoring
- Use Redis Cluster for high availability
Example Production Config:
# Production Redis with authentication
REDIS_URL=redis://:your-secure-password@redis-server:6379/0
REDIS_PASSWORD=your-secure-password
# Connection pool settings
REDIS_MAX_CONNECTIONS=20
REDIS_SOCKET_TIMEOUT=5
REDIS_SOCKET_CONNECT_TIMEOUT=5
Troubleshooting
Common Issues:
"Connection refused" (Error 10061)
- Redis server is not running
- Wrong host/port configuration
- Firewall blocking the connection
"Authentication failed"
- Wrong password in REDIS_URL
- Redis configured with auth but no password provided
"Connection timeout"
- Network issues
- Redis server overloaded
- Wrong host address
Debug Commands:
# Check if Redis is running
redis-cli ping
# Check Redis info
redis-cli info
# Monitor Redis commands
redis-cli monitor
# Check specific database
redis-cli -n 0 keys "*"
Development vs Production
Development (Local):
REDIS_URL=redis://localhost:6379/0
Testing (No Redis):
REDIS_URL=None
Production (Managed Redis):
REDIS_URL=redis://:password@your-redis-host:6379/0
Cloud Redis Services
For production, consider managed Redis services:
- AWS ElastiCache
- Google Cloud Memorystore
- Azure Cache for Redis
- Redis Cloud
- DigitalOcean Managed Redis
These provide:
- Automatic backups
- High availability
- Monitoring and alerts
- Security and compliance
- Automatic scaling
Summary
The Error 10061 occurs because Redis is not installed or running. You have three options:
- Install Redis (recommended for development/production)
- Use Docker to run Redis (easiest setup)
- Run without Redis (works but with performance impact)
The application gracefully handles Redis being unavailable and will continue to function using database-only operations.