@@ -118,22 +118,37 @@ export function createRedisProviders(): Array<Provider<RedisService>> {
118
118
export const redisProviders : Provider [ ] = [
119
119
{
120
120
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 ) ;
127
133
} ,
134
+ inject : [ ConfigService ] ,
128
135
} ,
129
136
{
130
137
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 ) ;
136
150
} ,
151
+ inject : [ ConfigService ] ,
137
152
} ,
138
153
// Prefix-based providers are appended at module initialisation time:
139
154
// ...createRedisProviders(),
0 commit comments