Overview
socket-serve requires Redis for:- Session state storage
- Pub/sub message broadcasting
- Room membership tracking
Development
Upstash
Managed serverless Redis service.Configuration
-
Account Setup
- Navigate to console.upstash.com
- Create account
-
Database Creation
- Create new database
- Select region
- Copy connection URL
-
Environment Configuration
.env.local: -
Verification
Local Redis
macOS:Docker Compose
Production Setup
Option 1: Upstash (Recommended for Serverless)
Why Upstash for Production?
- Serverless-native: Pay per request, scales to zero
- Global distribution: Multi-region support
- High availability: Built-in redundancy
- No connection limits: Perfect for serverless functions
- Low latency: Optimized for serverless platforms
Production Configuration
-
Upgrade Plan (if needed)
- Free tier: 10,000 requests/day
- Pay-as-you-go: $0.20 per 100K requests
- Pro: Fixed pricing with higher limits
-
Enable Multi-Region (optional)
- Global database for worldwide low latency
- Read replicas in multiple regions
-
Set Production Environment Variables
Vercel:
Netlify:AWS Lambda:
- Add to Lambda environment variables or Secrets Manager
Option 2: AWS ElastiCache
For AWS deployments:Option 3: Google Cloud Memorystore
Option 4: Azure Cache for Redis
Configuration Options
Basic Connection
With Authentication
With TLS
Connection Pool
Redis Cluster
Testing Connection
Test Script
Createtest-redis.ts:
Monitoring
Upstash Dashboard
- View real-time command statistics
- Monitor memory usage
- Check connection count
- Browse keys and values
- Execute Redis commands
Redis CLI Monitoring
CloudWatch (AWS)
Troubleshooting
Connection refused
Connection refused
Check Redis is running:Check Redis is listening:Check firewall:
Authentication failed
Authentication failed
Check password:In code:
SSL/TLS errors
SSL/TLS errors
Use Disable cert verification (dev only):
rediss:// (with two ‘s’):Connection timeout
Connection timeout
Increase timeout:
Memory issues
Memory issues
Check memory usage:Set max memory:
Best Practices
Security
- ✅ Use TLS in production (
rediss://) - ✅ Set strong password
- ✅ Use environment variables, never hardcode
- ✅ Restrict network access (VPC/firewall)
- ✅ Disable dangerous commands (CONFIG, FLUSHALL)
Performance
- ✅ Use connection pooling
- ✅ Set appropriate TTLs for keys
- ✅ Monitor memory usage
- ✅ Use pipelining for bulk operations
- ✅ Configure eviction policy
Reliability
- ✅ Enable persistence (AOF or RDB)
- ✅ Set up replication/clustering
- ✅ Monitor with alerts
- ✅ Regular backups
- ✅ Test failover procedures