@@ -311,22 +311,29 @@ export class RedisClientPool<
311311 if ( this . _self . #isOpen) return ; // TODO: throw error?
312312 this . _self . #isOpen = true ;
313313
314- let count = 0 ;
315314 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+
320326 try {
321- await this . _self . #create( true )
327+ await client . connect ( ) ;
328+ cache . setRedirectClient ( client ) ;
322329 } catch ( err ) {
323330 this . destroy ( ) ;
324331 throw err ;
325332 }
326333 }
327334
328335 const promises = [ ] ;
329- while ( promises . length + count < this . _self . #options. minimum ) {
336+ while ( promises . length < this . _self . #options. minimum ) {
330337 promises . push ( this . _self . #create( ) ) ;
331338 }
332339
@@ -348,18 +355,7 @@ export class RedisClientPool<
348355
349356 try {
350357 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) {
363359 this . _self . #clientSideCache. addClient ( node . value ) ;
364360 }
365361
@@ -453,12 +449,6 @@ export class RedisClientPool<
453449 for ( let i = 0 ; i < toDestroy ; i ++ ) {
454450 // TODO: shift vs pop
455451 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-
462452 this . #clientSideCache?. removeClient ( client ) ;
463453 client . destroy ( ) ;
464454 }
@@ -505,6 +495,10 @@ export class RedisClientPool<
505495 for ( const client of this . _self . #clientsInUse) {
506496 promises . push ( client . close ( ) ) ;
507497 }
498+
499+ if ( this . #clientSideCache instanceof PooledRedirectClientSideCache ) {
500+ promises . push ( this . #clientSideCache. close ( ) ) ;
501+ }
508502
509503 await Promise . all ( promises ) ;
510504
@@ -526,6 +520,11 @@ export class RedisClientPool<
526520 for ( const client of this . _self . #clientsInUse) {
527521 client . destroy ( ) ;
528522 }
523+
524+ if ( this . #clientSideCache instanceof PooledRedirectClientSideCache ) {
525+ this . #clientSideCache. destroy ( ) ;
526+ }
527+
529528 this . _self . #clientsInUse. reset ( ) ;
530529
531530 this . _self . #isOpen = false ;
0 commit comments