import Redis from "ioredis"; let client: Redis | null = null; export function getRedis(): Redis { if (client) return client; const url = process.env.REDIS_URL; if (!url) { throw new Error("REDIS_URL is required"); } client = new Redis(url, { maxRetriesPerRequest: 2 }); return client; } export async function closeRedis(): Promise { if (!client) return; await client.quit(); client = null; }