@@ -7,6 +7,7 @@ export class ClientRedis extends ClientProxy {
77 private readonly logger = new Logger ( ClientProxy . name ) ;
88 private readonly DEFAULT_URL = 'redis://localhost:6379' ;
99 private readonly url : string ;
10+
1011 private pub : redis . RedisClient ;
1112 private sub : redis . RedisClient ;
1213
@@ -19,17 +20,27 @@ export class ClientRedis extends ClientProxy {
1920
2021 sendSingleMessage ( msg , callback : Function ) {
2122 const pattern = JSON . stringify ( msg . pattern ) ;
22- const listener = ( channel , msg ) => {
23+ const subscription = ( channel , msg ) => {
2324 const { err, response } = JSON . parse ( msg ) ;
2425 callback ( err , response ) ;
2526
2627 this . sub . unsubscribe ( this . getResPatternName ( pattern ) ) ;
27- this . sub . removeListener ( 'message' , listener ) ;
28+ this . sub . removeListener ( 'message' , subscription ) ;
2829 } ;
29- this . sub . on ( 'message' , listener ) ;
3030
31+ this . sub . on ( 'message' , subscription ) ;
3132 this . sub . subscribe ( this . getResPatternName ( pattern ) ) ;
3233 this . pub . publish ( this . getAckPatternName ( pattern ) , JSON . stringify ( msg ) ) ;
34+
35+ return subscription ;
36+ }
37+
38+ getAckPatternName ( pattern : string ) : string {
39+ return `${ pattern } _ack` ;
40+ }
41+
42+ getResPatternName ( pattern : string ) : string {
43+ return `${ pattern } _res` ;
3344 }
3445
3546 private init ( ) {
@@ -48,12 +59,4 @@ export class ClientRedis extends ClientProxy {
4859 stream . on ( 'error' , ( err ) => this . logger . error ( err ) ) ;
4960 }
5061
51- private getAckPatternName ( pattern : string ) : string {
52- return `${ pattern } _ack` ;
53- }
54-
55- private getResPatternName ( pattern : string ) : string {
56- return `${ pattern } _res` ;
57- }
58-
5962}
0 commit comments