Redis & Caching Patterns
Redis usage for caching, session storage, and job queues in Ever Gauzy.
Overviewβ
Redis is used for several purposes in Gauzy:
| Use Case | Description |
|---|---|
| Caching | API response and query caching |
| Job Queues | BullMQ background job processing |
| Session Storage | Distributed session management |
| Real-time | Socket.IO adapter for multi-instance |
Configurationβ
| Variable | Description | Default |
|---|---|---|
REDIS_HOST | Redis host | localhost |
REDIS_PORT | Redis port | 6379 |
REDIS_PASSWORD | Redis password | β |
REDIS_TLS | Enable TLS | false |
BullMQ Job Queuesβ
Background jobs are processed using BullMQ with Redis:
import { InjectQueue } from "@nestjs/bull";
@Injectable()
export class MyService {
constructor(@InjectQueue("email") private emailQueue: Queue) {}
async sendEmail(data: EmailData) {
await this.emailQueue.add("send", data, {
attempts: 3,
backoff: { type: "exponential", delay: 1000 },
});
}
}
Cache Patternsβ
API Response Cachingβ
@Get('/expensive-query')
@UseInterceptors(CacheInterceptor)
@CacheTTL(300) // 5 minutes
async getExpensiveData() { ... }
Manual Cache Managementβ
@Injectable()
export class MyService {
constructor(@Inject(CACHE_MANAGER) private cache: Cache) {}
async getData(key: string) {
const cached = await this.cache.get(key);
if (cached) return cached;
const data = await this.fetchFromDB();
await this.cache.set(key, data, { ttl: 300 });
return data;
}
}
Related Pagesβ
- Scaling & High Availability β multi-instance setup
- Environment Variables β Redis config