mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 01:47:39 +00:00
feat: add redis (#1390)
This commit is contained in:
@@ -142,6 +142,12 @@ Generate token at https://pushover.net/apps/build.
|
||||
???+ note
|
||||
`PUSHOVER_EXPIRE` and `PUSHOVER_RETRY` are only used when `PUSHOVER_PRIORITY="2"`
|
||||
|
||||
## Redis
|
||||
|
||||
| Environment variable | Description |
|
||||
|:---:|---|
|
||||
| `REDIS_URL` | Connection string in format (redis://[username]:[password]@[host][:port]/[database-id]) (redis://localhost:6379/1) |
|
||||
|
||||
## Slack
|
||||
|
||||
| Environment variable | Description |
|
||||
@@ -190,4 +196,4 @@ Generate all Twitter keys at: https://developer.twitter.com/
|
||||
| `TWITCH_CLIENT_SECRET`| Twitch client secret |
|
||||
| `TWITCH_ACCESS_TOKEN` | Twitch access token |
|
||||
| `TWITCH_REFRESH_TOKEN` | Twitch refresh token |
|
||||
| `TWITCH_CHANNEL` | Twitch channel |
|
||||
| `TWITCH_CHANNEL` | Twitch channel |
|
||||
Generated
+42
@@ -979,6 +979,14 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/random-useragent/-/random-useragent-0.3.0.tgz",
|
||||
"integrity": "sha512-K6yHeQCCJJBvHeW1akRxXC8GnADsXmoRA2UdVEYITzD88U8Vk3lX+0c0A27j3CrAiic2I961glcnwScc9vUtWg=="
|
||||
},
|
||||
"@types/redis": {
|
||||
"version": "2.8.28",
|
||||
"resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.28.tgz",
|
||||
"integrity": "sha512-8l2gr2OQ969ypa7hFOeKqtFoY70XkHxISV0pAwmQ2nm6CSPb1brmTmqJCGGrekCo+pAZyWlNXr+Kvo6L/1wijA==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/request": {
|
||||
"version": "2.48.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.5.tgz",
|
||||
@@ -2957,6 +2965,11 @@
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"denque": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
|
||||
"integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
|
||||
},
|
||||
"des.js": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz",
|
||||
@@ -9700,6 +9713,35 @@
|
||||
"strip-indent": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-3.0.2.tgz",
|
||||
"integrity": "sha512-PNhLCrjU6vKVuMOyFu7oSP296mwBkcE6lrAjruBYG5LgdSqtRBoVQIylrMyVZD/lkF24RSNNatzvYag6HRBHjQ==",
|
||||
"requires": {
|
||||
"denque": "^1.4.1",
|
||||
"redis-commands": "^1.5.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"redis-commands": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.6.0.tgz",
|
||||
"integrity": "sha512-2jnZ0IkjZxvguITjFTrGiLyzQZcTvaw8DAaCXxZq/dsHXz7KfMQ3OUJy7Tz9vnRtZRVz6VRCPDvruvU8Ts44wQ=="
|
||||
},
|
||||
"redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60="
|
||||
},
|
||||
"redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
||||
"requires": {
|
||||
"redis-errors": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"regex-not": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@jef/pushbullet": "^2.4.3",
|
||||
"@slack/web-api": "^5.14.0",
|
||||
"@types/random-useragent": "^0.3.0",
|
||||
"@types/redis": "^2.8.28",
|
||||
"chalk": "^4.1.0",
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
"discord.js": "^12.5.1",
|
||||
@@ -48,6 +49,7 @@
|
||||
"puppeteer-extra-plugin-block-resources": "^2.2.7",
|
||||
"puppeteer-extra-plugin-stealth": "^2.6.5",
|
||||
"pushover-notifications": "^1.2.2",
|
||||
"redis": "^3.0.2",
|
||||
"top-user-agents": "^1.0.19",
|
||||
"twilio": "^3.54.1",
|
||||
"twitch": "^4.3.6",
|
||||
|
||||
@@ -279,6 +279,9 @@ const notifications = {
|
||||
token: envOrString(process.env.PUSHOVER_TOKEN),
|
||||
username: envOrString(process.env.PUSHOVER_USER)
|
||||
},
|
||||
redis: {
|
||||
url: envOrString(process.env.REDIS_URL)
|
||||
},
|
||||
slack: {
|
||||
channel: envOrString(process.env.SLACK_CHANNEL),
|
||||
token: envOrString(process.env.SLACK_TOKEN)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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