Redis Cache Integration¶
Redis is an in-memory data structure store that Atlas ERP relies on heavily for caching, session management, and message queues.
Primary Use Cases¶
- Session Management: Better Auth can be configured to store active sessions in Redis, allowing for incredibly fast validation without hitting the primary PostgreSQL database.
- Background Jobs: BullMQ uses Redis to store job data, manage queues, and coordinate worker processes (e.g., for email sending and payroll processing).
- Rate Limiting: The
ThrottlerGuarduses Redis to track request counts across multiple API instances, preventing abuse. - Data Caching: Frequently accessed, rarely changing data (like Chart of Accounts structures or permission matrices) can be cached in Redis to speed up API responses.
Configuration¶
Backend (apps/api/.env):
| Bash | |
|---|---|
NestJS Implementation¶
The connection is managed in apps/api/src/common/modules/redis.module.ts. We use standard Node.js Redis clients (ioredis is preferred due to its native support in BullMQ).
Recommended Hosting¶
- Local Development: Use Docker (
docker run -p 6379:6379 -d redis). - Free Tier / Serverless: Upstash offers an excellent Serverless Redis product with a generous free tier, perfect for Vercel/Render deployments.
- Enterprise: AWS ElastiCache, Google Cloud Memorystore, or Aiven.
Troubleshooting¶
If the API fails to start with connection errors, ensure: 1. Redis is running (redis-cli ping should return PONG). 2. The port is correct. 3. If using Upstash or a remote provider, ensure the REDIS_PASSWORD and connection strings are formatted exactly as provided by the host.