@@ -15,7 +15,6 @@ import { ClientClosedError, ClientOfflineError, DisconnectsClientError } from '.
15
15
import { URL } from 'url' ;
16
16
import { TcpSocketConnectOpts } from 'net' ;
17
17
import { PubSubType , PubSubListener , PubSubTypeListeners , ChannelListeners } from './pub-sub' ;
18
- import { callbackify } from 'util' ;
19
18
20
19
export interface RedisClientOptions <
21
20
M extends RedisModules = RedisModules ,
@@ -190,7 +189,7 @@ export default class RedisClient<
190
189
readonly #options?: RedisClientOptions < M , F , S > ;
191
190
readonly #socket: RedisSocket ;
192
191
readonly #queue: RedisCommandsQueue ;
193
- readonly #isolationPool: Pool < RedisClientType < M , F , S > > ;
192
+ #isolationPool? : Pool < RedisClientType < M , F , S > > ;
194
193
readonly #v4: Record < string , any > = { } ;
195
194
#selectedDB = 0 ;
196
195
@@ -223,16 +222,9 @@ export default class RedisClient<
223
222
this . #options = this . #initiateOptions( options ) ;
224
223
this . #queue = this . #initiateQueue( ) ;
225
224
this . #socket = this . #initiateSocket( ) ;
226
- this . #isolationPool = createPool ( {
227
- create : async ( ) => {
228
- const duplicate = this . duplicate ( {
229
- isolationPoolOptions : undefined
230
- } ) . on ( 'error' , err => this . emit ( 'error' , err ) ) ;
231
- await duplicate . connect ( ) ;
232
- return duplicate ;
233
- } ,
234
- destroy : client => client . disconnect ( )
235
- } , options ?. isolationPoolOptions ) ;
225
+ // should be initiated in connect, not here
226
+ // TODO: consider breaking in v5
227
+ this . #isolationPool = this . #initiateIsolationPool( ) ;
236
228
this . #legacyMode( ) ;
237
229
}
238
230
@@ -337,6 +329,19 @@ export default class RedisClient<
337
329
. on ( 'end' , ( ) => this . emit ( 'end' ) ) ;
338
330
}
339
331
332
+ #initiateIsolationPool( ) {
333
+ return createPool ( {
334
+ create : async ( ) => {
335
+ const duplicate = this . duplicate ( {
336
+ isolationPoolOptions : undefined
337
+ } ) . on ( 'error' , err => this . emit ( 'error' , err ) ) ;
338
+ await duplicate . connect ( ) ;
339
+ return duplicate ;
340
+ } ,
341
+ destroy : client => client . disconnect ( )
342
+ } , this . #options?. isolationPoolOptions ) ;
343
+ }
344
+
340
345
#legacyMode( ) : void {
341
346
if ( ! this . #options?. legacyMode ) return ;
342
347
@@ -422,6 +427,8 @@ export default class RedisClient<
422
427
}
423
428
424
429
connect ( ) : Promise < void > {
430
+ // see comment in constructor
431
+ this . #isolationPool ??= this . #initiateIsolationPool( ) ;
425
432
return this . #socket. connect ( ) ;
426
433
}
427
434
@@ -704,6 +711,7 @@ export default class RedisClient<
704
711
}
705
712
706
713
executeIsolated < T > ( fn : ( client : RedisClientType < M , F , S > ) => T | Promise < T > ) : Promise < T > {
714
+ if ( ! this . #isolationPool) return Promise . reject ( new ClientClosedError ( ) ) ;
707
715
return this . #isolationPool. use ( fn ) ;
708
716
}
709
717
@@ -802,8 +810,9 @@ export default class RedisClient<
802
810
}
803
811
804
812
async #destroyIsolationPool( ) : Promise < void > {
805
- await this . #isolationPool. drain ( ) ;
806
- await this . #isolationPool. clear ( ) ;
813
+ await this . #isolationPool! . drain ( ) ;
814
+ await this . #isolationPool! . clear ( ) ;
815
+ this . #isolationPool = undefined ;
807
816
}
808
817
809
818
ref ( ) : void {
0 commit comments