@@ -66,10 +66,6 @@ export function connectHandler(self) {
6666 } ) ;
6767 }
6868
69- if ( ! self . options . enableReadyCheck ) {
70- exports . readyHandler ( self ) ( ) ;
71- }
72-
7369 /*
7470 No need to keep the reference of DataHandler here
7571 because we don't need to do the cleanup.
@@ -79,27 +75,69 @@ export function connectHandler(self) {
7975 stringNumbers : self . options . stringNumbers ,
8076 } ) ;
8177
82- if ( self . options . enableReadyCheck ) {
83- self . _readyCheck ( function ( err , info ) {
84- if ( connectionEpoch !== self . connectionEpoch ) {
85- return ;
78+ const clientCommandPromises = [ ] ;
79+
80+ if ( self . options . connectionName ) {
81+ debug ( "set the connection name [%s]" , self . options . connectionName ) ;
82+ clientCommandPromises . push (
83+ self . client ( "setname" , self . options . connectionName ) . catch ( noop )
84+ ) ;
85+ }
86+
87+ if ( ! self . options . disableClientInfo ) {
88+ debug ( "set the client info" ) ;
89+ clientCommandPromises . push (
90+ getPackageMeta ( )
91+ . then ( ( packageMeta ) => {
92+ return self
93+ . client ( "SETINFO" , "LIB-VER" , packageMeta . version )
94+ . catch ( noop ) ;
95+ } )
96+ . catch ( noop )
97+ ) ;
98+
99+ clientCommandPromises . push (
100+ self
101+ . client (
102+ "SETINFO" ,
103+ "LIB-NAME" ,
104+ self . options ?. clientInfoTag
105+ ? `ioredis(${ self . options . clientInfoTag } )`
106+ : "ioredis"
107+ )
108+ . catch ( noop )
109+ ) ;
110+ }
111+
112+ Promise . all ( clientCommandPromises )
113+ . catch ( noop )
114+ . finally ( ( ) => {
115+ if ( ! self . options . enableReadyCheck ) {
116+ exports . readyHandler ( self ) ( ) ;
86117 }
87- if ( err ) {
88- if ( ! flushed ) {
89- self . recoverFromFatalError (
90- new Error ( "Ready check failed: " + err . message ) ,
91- err
92- ) ;
93- }
94- } else {
95- if ( self . connector . check ( info ) ) {
96- exports . readyHandler ( self ) ( ) ;
97- } else {
98- self . disconnect ( true ) ;
99- }
118+
119+ if ( self . options . enableReadyCheck ) {
120+ self . _readyCheck ( function ( err , info ) {
121+ if ( connectionEpoch !== self . connectionEpoch ) {
122+ return ;
123+ }
124+ if ( err ) {
125+ if ( ! flushed ) {
126+ self . recoverFromFatalError (
127+ new Error ( "Ready check failed: " + err . message ) ,
128+ err
129+ ) ;
130+ }
131+ } else {
132+ if ( self . connector . check ( info ) ) {
133+ exports . readyHandler ( self ) ( ) ;
134+ } else {
135+ self . disconnect ( true ) ;
136+ }
137+ }
138+ } ) ;
100139 }
101140 } ) ;
102- }
103141 } ;
104142}
105143
@@ -264,38 +302,6 @@ export function readyHandler(self) {
264302 ? self . prevCondition . select
265303 : self . condition . select ;
266304
267- if ( self . options . connectionName ) {
268- debug ( "set the connection name [%s]" , self . options . connectionName ) ;
269- self . client ( "setname" , self . options . connectionName ) . catch ( noop ) ;
270- }
271-
272- if ( ! self . options ?. disableClientInfo ) {
273- debug ( "set the client info" ) ;
274-
275- let version = null ;
276-
277- getPackageMeta ( )
278- . then ( ( packageMeta ) => {
279- version = packageMeta ?. version ;
280- } )
281- . catch ( noop )
282- . finally ( ( ) => {
283- self
284- . client ( "SETINFO" , "LIB-VER" , version )
285- . catch ( noop ) ;
286- } ) ;
287-
288- self
289- . client (
290- "SETINFO" ,
291- "LIB-NAME" ,
292- self . options ?. clientInfoTag
293- ? `ioredis(${ self . options . clientInfoTag } )`
294- : "ioredis"
295- )
296- . catch ( noop ) ;
297- }
298-
299305 if ( self . options . readOnly ) {
300306 debug ( "set the connection to readonly mode" ) ;
301307 self . readonly ( ) . catch ( noop ) ;
0 commit comments