File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import Redis from 'ioredis';
4
4
@Injectable ( )
5
5
export class RedisDomainService {
6
6
constructor (
7
- @Inject ( 'REDIS_CLIENT' )
8
- private readonly redis : Redis ,
7
+ @Inject ( 'REDIS_CLIENT' ) private readonly redis : Redis ,
8
+ @Inject ( 'REDIS_PUBLISHER' ) private readonly publisher : Redis ,
9
+ @Inject ( 'REDIS_SUBSCRIBER' ) private readonly subscriber : Redis ,
9
10
) { }
10
11
11
12
async exists ( key : string ) : Promise < number > {
@@ -64,11 +65,11 @@ export class RedisDomainService {
64
65
}
65
66
66
67
async publish ( channel : string , message : string ) {
67
- return this . redis . publish ( channel , message ) ;
68
+ return this . publisher . publish ( channel , message ) ;
68
69
}
69
70
70
71
async subscribe ( channel : string ) {
71
- await this . redis . subscribe ( channel ) ;
72
+ await this . subscriber . subscribe ( channel ) ;
72
73
}
73
74
74
75
on ( callback : ( message : string ) => void ) {
Original file line number Diff line number Diff line change @@ -15,6 +15,24 @@ import { RedisDomainService } from './redis.domain-service';
15
15
} ) ;
16
16
} ,
17
17
} ,
18
+ {
19
+ provide : 'REDIS_PUBLISHER' ,
20
+ useFactory : ( ) => {
21
+ return new Redis ( {
22
+ host : process . env . REDIS_HOST || 'redis' ,
23
+ port : Number ( process . env . REDIS_PORT || 6379 ) ,
24
+ } ) ;
25
+ } ,
26
+ } ,
27
+ {
28
+ provide : 'REDIS_SUBSCRIBER' ,
29
+ useFactory : ( ) => {
30
+ return new Redis ( {
31
+ host : process . env . REDIS_HOST || 'redis' ,
32
+ port : Number ( process . env . REDIS_PORT || 6379 ) ,
33
+ } ) ;
34
+ } ,
35
+ } ,
18
36
RedisDomainService ,
19
37
] ,
20
38
exports : [ RedisDomainService , 'REDIS_CLIENT' ] ,
You canโt perform that action at this time.
0 commit comments