mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
feat: add redis (#1390)
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user