Files
teknav-bak/app/backend/src/redis.ts
T
arsam 791f0ca64c Import source: app/backend/src/redis
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:19:51 +03:30

23 lines
785 B
TypeScript

// Single Redis client for the whole backend (sessions, rate-limit, view buffer).
// Lazy-connected so test suites can swap it out before connection.
import { Redis } from 'ioredis';
import { config } from './config.js';
export const redis = new Redis(config.REDIS_URL, {
lazyConnect: true,
// Reconnect with exponential backoff up to 5s; ioredis handles command queuing while reconnecting.
retryStrategy: (times: number) => Math.min(times * 200, 5000),
enableReadyCheck: true,
});
redis.on('error', (err: Error) => {
// Don't crash on transient errors — Fastify will surface 503s via /health.
console.error('[redis]', err.message);
});
export async function connectRedis() {
if (redis.status === 'wait' || redis.status === 'end') {
await redis.connect();
}
}