83 lines
1.5 KiB
Markdown
83 lines
1.5 KiB
Markdown
# Redis Cache Setup
|
|
|
|
## Lokale Installation
|
|
|
|
### macOS (mit Homebrew)
|
|
```bash
|
|
brew install redis
|
|
brew services start redis
|
|
```
|
|
|
|
### Docker
|
|
```bash
|
|
docker run -d -p 6379:6379 --name redis redis:latest
|
|
```
|
|
|
|
### Linux (Ubuntu/Debian)
|
|
```bash
|
|
sudo apt-get update
|
|
sudo apt-get install redis-server
|
|
sudo systemctl start redis
|
|
```
|
|
|
|
## Konfiguration
|
|
|
|
### Environment Variables
|
|
```bash
|
|
# Redis aktivieren
|
|
REDIS_ENABLED=true
|
|
|
|
# Redis-Verbindung (optional, Defaults: localhost:6379)
|
|
REDIS_HOST=localhost
|
|
REDIS_PORT=6379
|
|
REDIS_PASSWORD= # Optional, nur wenn gesetzt
|
|
```
|
|
|
|
### Beispiel .env Datei
|
|
```env
|
|
REDIS_ENABLED=true
|
|
REDIS_HOST=localhost
|
|
REDIS_PORT=6379
|
|
```
|
|
|
|
## Verwendung
|
|
|
|
### Redis aktivieren
|
|
```bash
|
|
REDIS_ENABLED=true npm run mock:server
|
|
```
|
|
|
|
### Ohne Redis (In-Memory Fallback)
|
|
```bash
|
|
# REDIS_ENABLED nicht setzen oder auf false
|
|
npm run mock:server
|
|
```
|
|
|
|
## Features
|
|
|
|
- ✅ **Automatischer Fallback**: Wenn Redis nicht verfügbar ist, wird automatisch In-Memory Cache verwendet
|
|
- ✅ **Retry-Logik**: Bei Verbindungsfehlern wird automatisch auf In-Memory umgeschaltet
|
|
- ✅ **Metrics**: Cache-Hits/Misses werden weiterhin getrackt
|
|
- ✅ **Logging**: Alle Redis-Operationen werden geloggt
|
|
|
|
## Testen
|
|
|
|
```bash
|
|
# Redis-Verbindung testen
|
|
redis-cli ping
|
|
# Sollte "PONG" zurückgeben
|
|
|
|
# Cache-Keys anzeigen
|
|
redis-cli keys "*"
|
|
|
|
# Cache leeren
|
|
redis-cli FLUSHALL
|
|
```
|
|
|
|
## Monitoring
|
|
|
|
Die Cache-Metriken sind weiterhin verfügbar unter:
|
|
- `http://localhost:9090/metrics` - Prometheus Metrics
|
|
- Logs zeigen Redis-Status und Fallback-Verhalten
|
|
|