chore(redis): init client once

Regression of 6bc7737ef0
This commit is contained in:
Jef LeCompte
2020-12-26 07:37:33 -08:00
parent 6bc7737ef0
commit a908ce417b
2 changed files with 5 additions and 6 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ import {sendTelegramMessage} from './telegram';
import {sendTweet} from './twitter'; import {sendTweet} from './twitter';
import {sendTwilioMessage} from './twilio'; import {sendTwilioMessage} from './twilio';
import {sendTwitchMessage} from './twitch'; import {sendTwitchMessage} from './twitch';
import updateRedis from './redis'; import {updateRedis} from './redis';
export function sendNotification(link: Link, store: Store) { export function sendNotification(link: Link, store: Store) {
// Priority // Priority
+4 -5
View File
@@ -4,19 +4,18 @@ import {config} from '../config';
import {logger} from '../logger'; import {logger} from '../logger';
const {url} = config.notifications.redis; const {url} = config.notifications.redis;
let client: RedisClient;
function initRedis(): RedisClient | null { function initRedis(): RedisClient | null {
if (url) { if (url) {
return redis.createClient({url}); client = redis.createClient({url});
} }
return null; return null;
} }
function updateRedis(link: Link, store: Store) { export function updateRedis(link: Link, store: Store) {
try { try {
const client = initRedis();
if (client) { if (client) {
const key = `${store.name}:${link.brand}:${link.model}` const key = `${store.name}:${link.brand}:${link.model}`
.split(' ') .split(' ')
@@ -43,4 +42,4 @@ function updateRedis(link: Link, store: Store) {
} }
} }
export default updateRedis; initRedis();