Files
classroomio/apps/api/src/utils/redis/redis.ts
T

37 lines
794 B
TypeScript
Raw Normal View History

2026-03-09 11:18:22 +01:00
import { createClient } from 'redis';
2025-11-01 15:49:29 +01:00
import { env } from '@api/config/env';
2026-03-09 11:18:22 +01:00
// Create Redis client
const client = createClient({
url: env.REDIS_URL
});
// Handle connection events
client.on('error', (err) => {
console.error('Redis Client Error:', err);
});
client.on('connect', () => {
console.log('Redis Client Connected');
});
client.on('reconnecting', () => {
console.log('Redis Client Reconnecting');
});
// Track connection state
let isConnected = false;
export async function connectRedis(): Promise<void> {
if (!isConnected) {
await client.connect();
isConnected = true;
}
}
// Export the client (connection will be established before server starts)
export const redis = client;
// Export type for use in other files
export type RedisClient = typeof client;