Files
Liam 1a5493be69
All checks were successful
deploy / deploy (push) Successful in 1m3s
change(ssr): re-connect to redis after 30s
2023-11-08 23:59:36 +00:00

29 lines
629 B
TypeScript

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