From 6bc7737ef04e5592e19b0b6a76e5fb0cd4b048df Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Sat, 26 Dec 2020 07:28:49 -0800 Subject: [PATCH] fix: disable redis if not configured Fixes #1516 --- src/notification/redis.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/notification/redis.ts b/src/notification/redis.ts index 037da83..de9542d 100644 --- a/src/notification/redis.ts +++ b/src/notification/redis.ts @@ -1,17 +1,23 @@ import {Link, Store} from '../store/model'; +import redis, {RedisClient} from 'redis'; import {config} from '../config'; import {logger} from '../logger'; -import redis from 'redis'; const {url} = config.notifications.redis; -const client = redis.createClient({ - url -}); +function initRedis(): RedisClient | null { + if (url) { + return redis.createClient({url}); + } -const updateRedis = (link: Link, store: Store) => { + return null; +} + +function updateRedis(link: Link, store: Store) { try { - if (url) { + const client = initRedis(); + + if (client) { const key = `${store.name}:${link.brand}:${link.model}` .split(' ') .join('-'); @@ -35,6 +41,6 @@ const updateRedis = (link: Link, store: Store) => { } catch (error: unknown) { logger.error("✖ couldn't update redis", error); } -}; +} export default updateRedis;