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
+14 -8
View File
@@ -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
});
const updateRedis = (link: Link, store: Store) => {
try {
function initRedis(): RedisClient | null {
if (url) {
return redis.createClient({url});
}
return null;
}
function updateRedis(link: Link, store: Store) {
try {
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;