From 37cd9ad3d7c3e36b33fd9ccfc598cebfb3ac27a9 Mon Sep 17 00:00:00 2001 From: Matan Mashraki <12946462+planecore@users.noreply.github.com> Date: Mon, 18 Dec 2023 23:11:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20-=20Hotfix=20Redis=20not=20conne?= =?UTF-8?q?cting=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/redis.ts | 19 +++++++++++-------- src/logs/logger.ts | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/data/redis.ts b/src/data/redis.ts index e9668d0..527b752 100644 --- a/src/data/redis.ts +++ b/src/data/redis.ts @@ -1,6 +1,6 @@ import { createClient } from "redis" import { RedisClientType } from "@redis/client" -import { compact, mapValues, omit } from "lodash" +import { compact, isEmpty, mapValues, omit } from "lodash" import { redisUrl } from "./config" import { Ride } from "../types/ride" @@ -9,13 +9,16 @@ import { logNames, logger } from "../logs" let client: RedisClientType export const connectToRedis = async () => { - try { - client = createClient({ url: redisUrl }) - await client.connect() - logger.info(logNames.redis.connect.success) - } catch (error) { - logger.error(logNames.redis.connect.failed, { error }) - } + client = createClient({ url: redisUrl }) + + client.on("error", (error) => { + if (!isEmpty(error)) { + logger.error(logNames.redis.connect.failed, { error }) + } + }) + + await client.connect() + logger.info(logNames.redis.connect.success) } export const addRide = async (ride: Ride): Promise => { diff --git a/src/logs/logger.ts b/src/logs/logger.ts index 8fa394e..e109911 100644 --- a/src/logs/logger.ts +++ b/src/logs/logger.ts @@ -32,6 +32,7 @@ export const startLogger = () => { db: mongoUrl, dbName: "logs" + (railwayEnviroment === "production" ? "" : `-${railwayEnviroment}`), format: serializeErrors(), + options: { poolSize: 2, useNewUrlParser: true, useUnifiedTopology: true }, }), ], })