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

Commit

Permalink
feat: add support for redis sentinel
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklason committed Mar 22, 2021
1 parent 0431ad7 commit ecca825
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/bull": "^3.15.0",
"@types/express": "^4.17.8",
"@types/ioredis": "^4.22.1",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@typescript-eslint/eslint-plugin": "^4.6.1",
Expand Down
23 changes: 20 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BullModule } from '@nestjs/bull';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import IORedis from 'ioredis';
import configuration, { QueueConfig } from './common/config/configuration';
import { validation } from './common/config/validation';
import { ScheamaModule } from './schema/schema.module';
Expand All @@ -19,12 +20,28 @@ import { ScheamaModule } from './schema/schema.module';
useFactory: (configService: ConfigService) => {
const queueConfig = configService.get<QueueConfig>('queue');

return {
redis: {
let redisConfig: IORedis.RedisOptions;

if (queueConfig.isSentinel) {
redisConfig = {
sentinels: [
{
host: queueConfig.host,
port: queueConfig.port,
},
],
name: queueConfig.set,
};
} else {
redisConfig = {
host: queueConfig.host,
port: queueConfig.port,
password: queueConfig.password,
},
};
}

return {
redis: redisConfig,
prefix: 'bull',
};
},
Expand Down
6 changes: 5 additions & 1 deletion src/common/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ export interface Services {
}

export interface QueueConfig {
isSentinel: boolean;
host: string;
port: number;
password: string;
password?: string;
set?: string;
}

export default (): Config => {
return {
steamApiKey: process.env.STEAM_API_KEY,
queue: {
isSentinel: process.env.QUEUE_IS_SENTINEL === 'true',
host: process.env.QUEUE_HOST,
port: parseInt(process.env.QUEUE_PORT, 10),
password: process.env.QUEUE_PASSWORD,
set: process.env.QUEUE_SET,
},
services: {
schema: process.env.SCHEMA_SERVICE_URL,
Expand Down
4 changes: 3 additions & 1 deletion src/common/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import * as Joi from 'joi';
const validation = Joi.object({
NODE_ENV: Joi.string().valid('development', 'production', 'test').required(),
STEAM_API_KEY: Joi.string().required(),
QUEUE_IS_SENTINEL: Joi.boolean().optional(),
QUEUE_HOST: Joi.string().required(),
QUEUE_PORT: Joi.number().required(),
QUEUE_PASSWORD: Joi.string().required(),
QUEUE_PASSWORD: Joi.string().optional(),
QUEUE_SET: Joi.string().optional(),
SCHEMA_SERVICE_URL: Joi.string().required(),
});

Expand Down

0 comments on commit ecca825

Please sign in to comment.