Re_Backend/UPSTASH_QUICK_REFERENCE.md

216 lines
3.6 KiB
Markdown

# 🚀 Upstash Redis - Quick Reference
## One-Time Setup (2 Minutes)
```
1. Visit: https://console.upstash.com/
└─ Sign up (free)
2. Create Database
└─ Name: redis-tat-dev
└─ Type: Regional
└─ Region: US-East-1 (or closest)
└─ Click "Create"
3. Copy Redis URL
└─ Format: rediss://default:PASSWORD@host.upstash.io:6379
└─ Click copy button 📋
4. Paste into .env
└─ Re_Backend/.env
└─ REDIS_URL=rediss://default:...
└─ TAT_TEST_MODE=true
5. Start Backend
└─ cd Re_Backend
└─ npm run dev
└─ ✅ See: "Connected to Redis"
```
---
## Environment Variables
```bash
# Re_Backend/.env
# Upstash Redis (paste your URL)
REDIS_URL=rediss://default:YOUR_PASSWORD@YOUR_HOST.upstash.io:6379
# Test Mode (1 hour = 1 minute)
TAT_TEST_MODE=true
# Working Hours (optional)
WORK_START_HOUR=9
WORK_END_HOUR=18
```
---
## Test TAT Notifications
```
1. Create Request
└─ TAT: 6 hours
└─ Submit request
2. Wait for Notifications (Test Mode)
└─ 3 minutes → ⏳ 50% alert
└─ 4.5 minutes → ⚠️ 75% warning
└─ 6 minutes → ⏰ 100% breach
3. Check Logs
└─ [TAT Scheduler] ✅ TAT jobs scheduled
└─ [TAT Processor] Processing tat50...
└─ [TAT Processor] tat50 notification sent
```
---
## Monitor in Upstash Console
```
1. Go to: https://console.upstash.com/
2. Click your database
3. Click "CLI" tab
4. Run commands:
PING
→ PONG
KEYS bull:tatQueue:*
→ Shows all queued TAT jobs
INFO
→ Shows Redis stats
```
---
## Troubleshooting
### ❌ Connection Error
```bash
# Check .env
REDIS_URL=rediss://... (correct URL?)
# Test in Upstash Console
# CLI tab → PING → should return PONG
# Restart backend
npm run dev
```
### ❌ No Notifications
```bash
# Checklist:
- ✅ REDIS_URL in .env?
- ✅ TAT_TEST_MODE=true?
- ✅ Backend restarted?
- ✅ Request SUBMITTED (not just created)?
- ✅ Logs show "Connected to Redis"?
```
---
## Production Setup
```bash
# Option 1: Use Upstash (same as dev)
REDIS_URL=rediss://default:PROD_PASSWORD@prod.upstash.io:6379
TAT_TEST_MODE=false
# Option 2: Linux server with native Redis
sudo apt install redis-server -y
sudo systemctl start redis-server
# Then in .env:
REDIS_URL=redis://localhost:6379
TAT_TEST_MODE=false
```
---
## Upstash Free Tier
```
✅ 10,000 commands/day (FREE forever)
✅ 256 MB storage
✅ TLS encryption
✅ Global CDN
✅ Zero maintenance
Perfect for:
- Development
- Testing
- Small production (<100 users)
```
---
## Commands Cheat Sheet
### Upstash Console CLI
```redis
# Test connection
PING
# List all keys
KEYS *
# Count keys
DBSIZE
# View queued jobs
KEYS bull:tatQueue:*
# Get job details
HGETALL bull:tatQueue:tat50-<REQUEST_ID>-<LEVEL_ID>
# Clear all data (CAREFUL!)
FLUSHALL
# Get server info
INFO
# Monitor live commands
MONITOR
```
---
## Quick Links
- **Upstash Console**: https://console.upstash.com/
- **Upstash Docs**: https://docs.upstash.com/redis
- **Full Setup Guide**: `docs/UPSTASH_SETUP_GUIDE.md`
- **TAT System Docs**: `docs/TAT_NOTIFICATION_SYSTEM.md`
- **Quick Start**: `TAT_QUICK_START.md`
---
## Support
**Connection Issues?**
1. Verify URL format: `rediss://` (double 's')
2. Check Upstash database status (should be "Active")
3. Test in Upstash Console CLI
**Need Help?**
- Check logs: `Get-Content logs/app.log -Tail 50 -Wait`
- Review docs: `docs/UPSTASH_SETUP_GUIDE.md`
---
**✅ Setup Complete? Start Testing!**
Create a 6-hour TAT request and watch notifications arrive in 3, 4.5, and 6 minutes!
---
**Last Updated**: November 4, 2025