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
+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;