Skip to content

Commit

Permalink
feat(redis): introduce pub/sub (#2855)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalette authored Dec 15, 2021
1 parent 72140be commit d6d8ef2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions dotenv-example
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ PUSHOVER_RETRY=
PUSHOVER_SOUND=
PUSHOVER_TOKEN=
PUSHOVER_USER=
REDIS_URL=
RESTART_TIME=
SCREENSHOT=
SCREENSHOT_DIR=
Expand Down
23 changes: 16 additions & 7 deletions src/messaging/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ export function updateRedis(link: Link, store: Store) {
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})`);
}
const message = JSON.stringify(value);
client.set(key, message, (error, success) => {
if (error) {
logger.error(`✖ couldn't update redis for key (${key})`);
} else {
logger.info('✔ redis updated');
}
});

client.publish('streetmerchant', message, (error, success) => {
if (error) {
logger.error(`✖ couldn't publish to redis`);
} else {
logger.info('✔ redis message published');
}
});
}
} catch (error: unknown) {
logger.error("✖ couldn't update redis", error);
Expand Down

0 comments on commit d6d8ef2

Please sign in to comment.