fix: disable redis if not configured

Fixes #1516
This commit is contained in:
Jef LeCompte
2020-12-26 07:28:49 -08:00
parent 14998d87f9
commit 6bc7737ef0
+13 -7
View File
@@ -1,17 +1,23 @@
import {Link, Store} from '../store/model'; import {Link, Store} from '../store/model';
import redis, {RedisClient} from 'redis';
import {config} from '../config'; import {config} from '../config';
import {logger} from '../logger'; import {logger} from '../logger';
import redis from 'redis';
const {url} = config.notifications.redis; const {url} = config.notifications.redis;
const client = redis.createClient({ function initRedis(): RedisClient | null {
url if (url) {
}); return redis.createClient({url});
}
const updateRedis = (link: Link, store: Store) => { return null;
}
function updateRedis(link: Link, store: Store) {
try { try {
if (url) { const client = initRedis();
if (client) {
const key = `${store.name}:${link.brand}:${link.model}` const key = `${store.name}:${link.brand}:${link.model}`
.split(' ') .split(' ')
.join('-'); .join('-');
@@ -35,6 +41,6 @@ const updateRedis = (link: Link, store: Store) => {
} catch (error: unknown) { } catch (error: unknown) {
logger.error("✖ couldn't update redis", error); logger.error("✖ couldn't update redis", error);
} }
}; }
export default updateRedis; export default updateRedis;