@@ -160,9 +160,7 @@ public void FailoverTo(IEnumerable<string> readWriteHosts, IEnumerable<string> r
160160 {
161161 var redis = readClients [ i ] ;
162162 if ( redis != null )
163- {
164- redis . DisposeConnection ( ) ;
165- }
163+ RedisState . DeactivateClient ( redis ) ;
166164
167165 readClients [ i ] = null ;
168166 }
@@ -175,9 +173,7 @@ public void FailoverTo(IEnumerable<string> readWriteHosts, IEnumerable<string> r
175173 {
176174 var redis = writeClients [ i ] ;
177175 if ( redis != null )
178- {
179- redis . DisposeConnection ( ) ;
180- }
176+ RedisState . DeactivateClient ( redis ) ;
181177
182178 writeClients [ i ] = null ;
183179 }
@@ -233,6 +229,8 @@ public IRedisClient GetClient()
233229
234230 InitClient ( inActiveClient ) ;
235231
232+ RedisState . DisposeExpiredClients ( ) ;
233+
236234 return inActiveClient ;
237235 }
238236 }
@@ -250,7 +248,6 @@ private RedisClient GetInActiveWriteClient()
250248 for ( int x = 0 ; x < readWriteTotal ; x ++ )
251249 {
252250 var nextHostIndex = ( desiredIndex + x ) % readWriteTotal ;
253- RedisEndpoint nextHost = RedisResolver . GetReadWriteHost ( nextHostIndex ) ;
254251 for ( var i = nextHostIndex ; i < writeClients . Length ; i += readWriteTotal )
255252 {
256253 if ( writeClients [ i ] != null && ! writeClients [ i ] . Active && ! writeClients [ i ] . HadExceptions )
@@ -259,9 +256,10 @@ private RedisClient GetInActiveWriteClient()
259256 if ( writeClients [ i ] == null || writeClients [ i ] . HadExceptions )
260257 {
261258 if ( writeClients [ i ] != null )
262- writeClients [ i ] . DisposeConnection ( ) ;
259+ RedisState . DeactivateClient ( writeClients [ i ] ) ;
263260
264- var client = InitNewClient ( nextHost , readWrite : true ) ;
261+ var nextHost = RedisResolver . GetReadWriteHost ( nextHostIndex ) ;
262+ var client = InitNewClient ( nextHost , readWrite : true ) ;
265263 writeClients [ i ] = client ;
266264
267265 return client ;
@@ -330,6 +328,8 @@ public virtual IRedisClient GetReadOnlyClient()
330328
331329 InitClient ( inActiveClient ) ;
332330
331+ RedisState . DisposeExpiredClients ( ) ;
332+
333333 return inActiveClient ;
334334 }
335335 }
@@ -347,7 +347,6 @@ private RedisClient GetInActiveReadClient()
347347 for ( int x = 0 ; x < readOnlyTotal ; x ++ )
348348 {
349349 var nextHostIndex = ( desiredIndex + x ) % readOnlyTotal ;
350- var nextHost = RedisResolver . GetReadOnlyHost ( nextHostIndex ) ;
351350 for ( var i = nextHostIndex ; i < readClients . Length ; i += readOnlyTotal )
352351 {
353352 if ( readClients [ i ] != null && ! readClients [ i ] . Active && ! readClients [ i ] . HadExceptions )
@@ -356,9 +355,10 @@ private RedisClient GetInActiveReadClient()
356355 if ( readClients [ i ] == null || readClients [ i ] . HadExceptions )
357356 {
358357 if ( readClients [ i ] != null )
359- readClients [ i ] . DisposeConnection ( ) ;
358+ RedisState . DeactivateClient ( readClients [ i ] ) ;
360359
361- var client = InitNewClient ( nextHost , readWrite : false ) ;
360+ var nextHost = RedisResolver . GetReadOnlyHost ( nextHostIndex ) ;
361+ var client = InitNewClient ( nextHost , readWrite : false ) ;
362362 readClients [ i ] = client ;
363363
364364 return client ;
@@ -597,6 +597,8 @@ protected virtual void Dispose(bool disposing)
597597 {
598598 Log . Error ( "Error when trying to dispose of PooledRedisClientManager" , ex ) ;
599599 }
600+
601+ RedisState . DisposeAllDeactivatedClients ( ) ;
600602 }
601603
602604 private int disposeAttempts = 0 ;
0 commit comments