Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Commit ecca825

Browse files
committed
feat: add support for redis sentinel
1 parent 0431ad7 commit ecca825

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@semantic-release/release-notes-generator": "^9.0.1",
4444
"@types/bull": "^3.15.0",
4545
"@types/express": "^4.17.8",
46+
"@types/ioredis": "^4.22.1",
4647
"@types/jest": "^26.0.15",
4748
"@types/node": "^14.14.6",
4849
"@typescript-eslint/eslint-plugin": "^4.6.1",

src/app.module.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BullModule } from '@nestjs/bull';
22
import { Module } from '@nestjs/common';
33
import { ConfigModule, ConfigService } from '@nestjs/config';
4+
import IORedis from 'ioredis';
45
import configuration, { QueueConfig } from './common/config/configuration';
56
import { validation } from './common/config/validation';
67
import { ScheamaModule } from './schema/schema.module';
@@ -19,12 +20,28 @@ import { ScheamaModule } from './schema/schema.module';
1920
useFactory: (configService: ConfigService) => {
2021
const queueConfig = configService.get<QueueConfig>('queue');
2122

22-
return {
23-
redis: {
23+
let redisConfig: IORedis.RedisOptions;
24+
25+
if (queueConfig.isSentinel) {
26+
redisConfig = {
27+
sentinels: [
28+
{
29+
host: queueConfig.host,
30+
port: queueConfig.port,
31+
},
32+
],
33+
name: queueConfig.set,
34+
};
35+
} else {
36+
redisConfig = {
2437
host: queueConfig.host,
2538
port: queueConfig.port,
2639
password: queueConfig.password,
27-
},
40+
};
41+
}
42+
43+
return {
44+
redis: redisConfig,
2845
prefix: 'bull',
2946
};
3047
},

src/common/config/configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ export interface Services {
99
}
1010

1111
export interface QueueConfig {
12+
isSentinel: boolean;
1213
host: string;
1314
port: number;
14-
password: string;
15+
password?: string;
16+
set?: string;
1517
}
1618

1719
export default (): Config => {
1820
return {
1921
steamApiKey: process.env.STEAM_API_KEY,
2022
queue: {
23+
isSentinel: process.env.QUEUE_IS_SENTINEL === 'true',
2124
host: process.env.QUEUE_HOST,
2225
port: parseInt(process.env.QUEUE_PORT, 10),
2326
password: process.env.QUEUE_PASSWORD,
27+
set: process.env.QUEUE_SET,
2428
},
2529
services: {
2630
schema: process.env.SCHEMA_SERVICE_URL,

src/common/config/validation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import * as Joi from 'joi';
33
const validation = Joi.object({
44
NODE_ENV: Joi.string().valid('development', 'production', 'test').required(),
55
STEAM_API_KEY: Joi.string().required(),
6+
QUEUE_IS_SENTINEL: Joi.boolean().optional(),
67
QUEUE_HOST: Joi.string().required(),
78
QUEUE_PORT: Joi.number().required(),
8-
QUEUE_PASSWORD: Joi.string().required(),
9+
QUEUE_PASSWORD: Joi.string().optional(),
10+
QUEUE_SET: Joi.string().optional(),
911
SCHEMA_SERVICE_URL: Joi.string().required(),
1012
});
1113

0 commit comments

Comments
 (0)