@@ -311,22 +311,29 @@ export class RedisClientPool<
311
311
if ( this . _self . #isOpen) return ; // TODO: throw error?
312
312
this . _self . #isOpen = true ;
313
313
314
- let count = 0 ;
315
314
if ( this . _self . #clientSideCache instanceof PooledRedirectClientSideCache ) {
316
- if ( this . _self . #options. minimum < 1 ) {
317
- this . _self . #options. minimum = 1 ;
318
- }
319
- count = 1 ;
315
+ const client = this . _self . #clientFactory( ) ;
316
+ const cache = this . _self . #clientSideCache;
317
+ client . on ( "error" , ( ) => {
318
+ cache . disable ( ) ;
319
+ cache . clear ( ) ;
320
+ } ) . on ( "ready" , async ( ) => {
321
+ const clientId = await client . clientId ( ) as number ;
322
+ cache . updateRedirect ( clientId ) ;
323
+ cache . enable ( ) ;
324
+ } )
325
+
320
326
try {
321
- await this . _self . #create( true )
327
+ await client . connect ( ) ;
328
+ cache . setRedirectClient ( client ) ;
322
329
} catch ( err ) {
323
330
this . destroy ( ) ;
324
331
throw err ;
325
332
}
326
333
}
327
334
328
335
const promises = [ ] ;
329
- while ( promises . length + count < this . _self . #options. minimum ) {
336
+ while ( promises . length < this . _self . #options. minimum ) {
330
337
promises . push ( this . _self . #create( ) ) ;
331
338
}
332
339
@@ -348,18 +355,7 @@ export class RedisClientPool<
348
355
349
356
try {
350
357
const client = node . value ;
351
- const cache = this . _self . #clientSideCache;
352
- if ( redirect && cache instanceof PooledRedirectClientSideCache ) {
353
- client . setAnnotation ( "pool-master" , "true" ) ;
354
- client . on ( "error" , ( ) => {
355
- cache . disable ( ) ;
356
- } ) . on ( "ready" , async ( ) => {
357
- const clientId = await client . clientId ( ) as number ;
358
- cache . updateRedirect ( clientId ) ;
359
- cache . clearPool ( ) ;
360
- cache . enable ( ) ;
361
- } )
362
- } else if ( this . _self . #clientSideCache) {
358
+ if ( this . _self . #clientSideCache) {
363
359
this . _self . #clientSideCache. addClient ( node . value ) ;
364
360
}
365
361
@@ -453,12 +449,6 @@ export class RedisClientPool<
453
449
for ( let i = 0 ; i < toDestroy ; i ++ ) {
454
450
// TODO: shift vs pop
455
451
const client = this . #idleClients. shift ( ) !
456
- if ( client . hasAnnotation ( "pool-master" ) ) {
457
- console . log ( "wanted to remove \"master\"/\"redirect\" client" ) ;
458
- this . _self . #idleClients. push ( client ) ;
459
- continue ;
460
- }
461
-
462
452
this . #clientSideCache?. removeClient ( client ) ;
463
453
client . destroy ( ) ;
464
454
}
@@ -505,6 +495,10 @@ export class RedisClientPool<
505
495
for ( const client of this . _self . #clientsInUse) {
506
496
promises . push ( client . close ( ) ) ;
507
497
}
498
+
499
+ if ( this . #clientSideCache instanceof PooledRedirectClientSideCache ) {
500
+ promises . push ( this . #clientSideCache. close ( ) ) ;
501
+ }
508
502
509
503
await Promise . all ( promises ) ;
510
504
@@ -526,6 +520,11 @@ export class RedisClientPool<
526
520
for ( const client of this . _self . #clientsInUse) {
527
521
client . destroy ( ) ;
528
522
}
523
+
524
+ if ( this . #clientSideCache instanceof PooledRedirectClientSideCache ) {
525
+ this . #clientSideCache. destroy ( ) ;
526
+ }
527
+
529
528
this . _self . #clientsInUse. reset ( ) ;
530
529
531
530
this . _self . #isOpen = false ;
0 commit comments