feat: add redis (#1390)

This commit is contained in:
Bailey Miller
2020-12-25 19:14:21 -05:00
committed by GitHub
parent 90fb430b71
commit fb82526a42
6 changed files with 96 additions and 1 deletions
+2
View File
@@ -14,6 +14,7 @@ import {sendTelegramMessage} from './telegram';
import {sendTweet} from './twitter';
import {sendTwilioMessage} from './twilio';
import {sendTwitchMessage} from './twitch';
import updateRedis from './redis';
export function sendNotification(link: Link, store: Store) {
// Priority
@@ -33,4 +34,5 @@ export function sendNotification(link: Link, store: Store) {
sendTweet(link, store);
sendTwilioMessage(link, store);
sendTwitchMessage(link, store);
updateRedis(link, store);
}
+40
View File
@@ -0,0 +1,40 @@
import {Link, Store} from '../store/model';
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 {
if (url) {
const key = `${store.name}:${link.brand}:${link.model}`
.split(' ')
.join('-');
const value = {
...link,
labels: store.labels,
links: store.links,
name: store.name,
updatedAt: new Date().toUTCString()
};
const redisUpdated = client.set(key, JSON.stringify(value));
if (redisUpdated) {
logger.info('✔ redis updated');
} else {
logger.error(`✖ couldn't update redis for key (${key})`);
}
}
} catch (error: unknown) {
logger.error("✖ couldn't update redis", error);
}
};
export default updateRedis;