Skip to content

Commit c861a1d

Browse files
Updated redis factory to use config values + ssl / password.
1 parent 76ae547 commit c861a1d

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/common/redis/redis.providers.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,37 @@ export function createRedisProviders(): Array<Provider<RedisService>> {
118118
export const redisProviders: Provider[] = [
119119
{
120120
provide: REDIS_SUBSCRIBER_CLIENT,
121-
useFactory: (): Redis => {
122-
return new IORedis({
123-
host: '127.0.0.1',
124-
port: 6379,
125-
// password: '', // uncomment if you need it
126-
});
121+
useFactory: (cfg: ConfigService): Redis => {
122+
const host = cfg.get('QUEUE_REDIS_HOST');
123+
const port = cfg.get('QUEUE_REDIS_PORT');
124+
const password = cfg.get('QUEUE_REDIS_PASSWORD');
125+
const useTls = cfg.get('QUEUE_REDIS_USE_TLS');
126+
const options: any = {
127+
host,
128+
port,
129+
...(password ? { password } : {}),
130+
...(useTls ? { tls: { servername: host } } : {}),
131+
};
132+
return new IORedis(options);
127133
},
134+
inject: [ConfigService],
128135
},
129136
{
130137
provide: REDIS_PUBLISHER_CLIENT,
131-
useFactory: (): Redis => {
132-
return new IORedis({
133-
host: '127.0.0.1',
134-
port: 6379,
135-
});
138+
useFactory: (cfg: ConfigService): Redis => {
139+
const host = cfg.get('QUEUE_REDIS_HOST');
140+
const port = cfg.get('QUEUE_REDIS_PORT');
141+
const password = cfg.get('QUEUE_REDIS_PASSWORD');
142+
const useTls = cfg.get('QUEUE_REDIS_USE_TLS');
143+
const options: any = {
144+
host,
145+
port,
146+
...(password ? { password } : {}),
147+
...(useTls ? { tls: { servername: host } } : {}),
148+
};
149+
return new IORedis(options);
136150
},
151+
inject: [ConfigService],
137152
},
138153
// Prefix-based providers are appended at module initialisation time:
139154
// ...createRedisProviders(),

0 commit comments

Comments
 (0)