@@ -123,6 +123,8 @@ public class RedisSentinel : IRedisSentinel
123123 /// </summary>
124124 public bool ResetWhenObjectivelyDown { get ; set ; }
125125
126+ internal string DebugId => $ "" ;
127+
126128 public RedisSentinel ( string sentinelHost = null , string masterName = null )
127129 : this ( new [ ] { sentinelHost ?? DefaultAddress } , masterName ?? DefaultMasterName ) { }
128130
@@ -287,10 +289,8 @@ private IRedisClientsManager CreateRedisManager(SentinelInfo sentinelInfo)
287289 return redisManager ;
288290 }
289291
290- public IRedisClientsManager GetRedisManager ( )
291- {
292- return RedisManager ?? ( RedisManager = CreateRedisManager ( GetSentinelInfo ( ) ) ) ;
293- }
292+ public IRedisClientsManager GetRedisManager ( ) =>
293+ RedisManager ??= CreateRedisManager ( GetSentinelInfo ( ) ) ;
294294
295295 private RedisSentinelWorker GetValidSentinelWorker ( )
296296 {
@@ -304,17 +304,30 @@ private RedisSentinelWorker GetValidSentinelWorker()
304304
305305 while ( this . worker == null && ShouldRetry ( ) )
306306 {
307+ var step = 0 ;
307308 try
308309 {
309310 this . worker = GetNextSentinel ( ) ;
311+ step = 1 ;
310312 GetRedisManager ( ) ;
311313
314+ step = 2 ;
312315 this . worker . BeginListeningForConfigurationChanges ( ) ;
313316 this . failures = 0 ; //reset
314317 return this . worker ;
315318 }
316319 catch ( RedisException ex )
317320 {
321+ if ( Log . IsDebugEnabled )
322+ {
323+ var name = step switch {
324+ 0 => "GetNextSentinel()" ,
325+ 1 => "GetRedisManager()" ,
326+ 2 => "BeginListeningForConfigurationChanges()" ,
327+ } ;
328+ Log . Debug ( $ "Failed to { name } : { ex . Message } ") ;
329+ }
330+
318331 if ( OnWorkerError != null )
319332 OnWorkerError ( ex ) ;
320333
@@ -378,6 +391,9 @@ private RedisSentinelWorker GetNextSentinel()
378391
379392 if ( ++ sentinelIndex >= SentinelEndpoints . Length )
380393 sentinelIndex = 0 ;
394+
395+ if ( Log . IsDebugEnabled )
396+ Log . Debug ( $ "Attempt to connect to next sentinel '{ SentinelEndpoints [ sentinelIndex ] } '...") ;
381397
382398 var sentinelWorker = new RedisSentinelWorker ( this , SentinelEndpoints [ sentinelIndex ] )
383399 {
@@ -443,6 +459,6 @@ public SentinelInfo(string masterName, IEnumerable<string> redisMasters, IEnumer
443459
444460 public override string ToString ( )
445461 {
446- return $ "{ MasterName } masters : { string . Join ( ", " , RedisMasters ) } , slaves : { string . Join ( ", " , RedisSlaves ) } ";
462+ return $ "{ MasterName } primary : { string . Join ( ", " , RedisMasters ) } , replicas : { string . Join ( ", " , RedisSlaves ) } ";
447463 }
448464}
0 commit comments