@@ -484,6 +484,15 @@ export default class RedisClient<
484
484
return this . _self . #dirtyWatch !== undefined
485
485
}
486
486
487
+ get socket ( ) {
488
+ return this . _self . #socket;
489
+ }
490
+
491
+ set socket ( socket : RedisSocket ) {
492
+ this . _self . #socket = socket ;
493
+ this . #initiateSocket( ) ;
494
+ }
495
+
487
496
/**
488
497
* Marks the client's WATCH command as invalidated due to a topology change.
489
498
* This will cause any subsequent EXEC in a transaction to fail with a WatchError.
@@ -581,6 +590,7 @@ export default class RedisClient<
581
590
}
582
591
583
592
}
593
+
584
594
#initiateOptions( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
585
595
586
596
// Convert username/password to credentialsProvider if no credentialsProvider is already in place
@@ -785,6 +795,29 @@ export default class RedisClient<
785
795
786
796
async #initiateSocket( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : Promise < void > {
787
797
await this . #socket. waitForReady ( ) ;
798
+
799
+ this . #socket
800
+ . on ( 'data' , chunk => {
801
+ try {
802
+ this . #queue. decoder . write ( chunk ) ;
803
+ } catch ( err ) {
804
+ this . #queue. resetDecoder ( ) ;
805
+ this . emit ( 'error' , err ) ;
806
+ }
807
+ } )
808
+ . on ( 'error' , err => {
809
+ this . emit ( 'error' , err ) ;
810
+ this . #clientSideCache?. onError ( ) ;
811
+ if ( this . #socket. isOpen && ! this . #options?. disableOfflineQueue ) {
812
+ this . #queue. flushWaitingForReply ( err ) ;
813
+ } else {
814
+ this . #queue. flushAll ( err ) ;
815
+ }
816
+ } )
817
+ . on ( 'reconnecting' , ( ) => this . emit ( 'reconnecting' ) )
818
+ . on ( 'drain' , ( ) => this . #maybeScheduleWrite( ) )
819
+ . on ( 'end' , ( ) => this . emit ( 'end' ) ) ;
820
+
788
821
console . log ( 'Initiator...' ) ;
789
822
const promises = [ ] ;
790
823
const chainId = Symbol ( 'Socket Initiator' ) ;
@@ -819,31 +852,11 @@ export default class RedisClient<
819
852
820
853
#createSocket( options ?: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisSocket {
821
854
return new RedisSocket ( options ?. socket )
822
- . on ( 'data' , chunk => {
823
- try {
824
- this . #queue. decoder . write ( chunk ) ;
825
- } catch ( err ) {
826
- this . #queue. resetDecoder ( ) ;
827
- this . emit ( 'error' , err ) ;
828
- }
829
- } )
830
- . on ( 'error' , err => {
831
- this . emit ( 'error' , err ) ;
832
- this . #clientSideCache?. onError ( ) ;
833
- if ( this . #socket. isOpen && ! this . #options?. disableOfflineQueue ) {
834
- this . #queue. flushWaitingForReply ( err ) ;
835
- } else {
836
- this . #queue. flushAll ( err ) ;
837
- }
838
- } )
839
855
. on ( 'connect' , ( ) => this . emit ( 'connect' ) )
840
856
. on ( 'ready' , ( ) => {
841
857
console . log ( 'Socket ready' ) ;
842
858
this . emit ( 'ready' ) ;
843
- } )
844
- . on ( 'reconnecting' , ( ) => this . emit ( 'reconnecting' ) )
845
- . on ( 'drain' , ( ) => this . #maybeScheduleWrite( ) )
846
- . on ( 'end' , ( ) => this . emit ( 'end' ) ) ;
859
+ } ) ;
847
860
}
848
861
849
862
#pingTimer?: NodeJS . Timeout ;
0 commit comments