Files
scoresaber-reloaded-v2/src/db/redis.ts

29 lines
629 B
TypeScript
Raw Normal View History

2023-11-08 23:17:32 +00:00
import { createClient } from "redis";
let redisClient = await connectRedis();
2023-11-08 23:17:32 +00:00
async function connectRedis(): Promise<any> {
2023-11-08 23:17:32 +00:00
console.log("Connecting to redis");
const client = createClient({
url: process.env.REDIS_URL,
});
await client.connect();
console.log("Connected to redis");
2023-11-08 23:17:32 +00:00
client.on("error", (error) => {
console.error("There was an error connecting to redis: " + error);
setTimeout(async () => {
redisClient = await connectRedis();
}, 30_000); // 30 seconds
2023-11-08 23:17:32 +00:00
});
return client;
}
// todo: add disconnect handler
export const Redis = {
client: redisClient,
connectRedis,
};