From dc9dabca488d35f8013882e6cde6c44a45aa2f31 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Wed, 15 May 2024 12:00:51 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fixed=20REDIS=5FURI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/redis.config.ts | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/config/redis.config.ts b/config/redis.config.ts index df743ae..18dcd27 100644 --- a/config/redis.config.ts +++ b/config/redis.config.ts @@ -1,47 +1,24 @@ import { createClient } from "redis"; -import { URL } from "url"; -// Ensure that the REDIS_URI environment variable is set const redisURL = process.env.REDIS_URI; -if (!redisURL) { - throw new Error("REDIS_URI environment variable is not set."); -} +if (!redisURL) throw new Error("REDIS_URI environment variable is not set."); -// Function to create a Redis client const createRedisClient = (url) => { const client = createClient({ url }); - console.log(client) - client.on("error", (err) => { - console.error("Redis Client Error", err); - }); - client.on("connect", () => { - console.log("Connected to Redis:", url); - }); + client.on("error", (err) => console.error("Redis Client Error", err)); + client.on("connect", () => console.log("Connected to Redis:", url)); + client.on("reconnecting", () => console.log("Reconnecting to Redis...")); - client.on("reconnecting", () => { - console.log("Reconnecting to Redis..."); - }); - - // Attempt to connect with error handling - client.connect().catch((err) => { - console.error("Failed to connect to Redis:", err); - }); + client.connect().catch((err) => console.error("Failed to connect to Redis:", err)); return client; }; -// Create publisher and subscriber clients -const pubClient = createRedisClient(process.env.REDIS_URI); +const pubClient = createRedisClient(redisURL); const subClient = pubClient.duplicate(); -// Ensure subscriber client handles connection and errors -subClient.on("error", (err) => { - console.error("Redis Subscriber Client Error", err); -}); - -subClient.connect().catch((err) => { - console.error("Failed to connect Redis Subscriber:", err); -}); +subClient.on("error", (err) => console.error("Redis Subscriber Client Error", err)); +subClient.connect().catch((err) => console.error("Failed to connect Redis Subscriber:", err)); export { subClient, pubClient };