You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
423 B
19 lines
423 B
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<void> {
|
|
if (!client) return;
|
|
await client.quit();
|
|
client = null;
|
|
}
|
|
|