Skip to content

Commit

Permalink
- optimize: SentinelAdapter switching exception #113
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Sep 15, 2022
1 parent 9f64871 commit dc91206
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/FreeRedis/RedisClient/Adapter/SentinelAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class SentinelAdapter : BaseAdapter
string _masterHost;
readonly bool _rw_splitting;
readonly bool _is_single;
Exception _switchingException;

public SentinelAdapter(RedisClient topOwner, ConnectionStringBuilder sentinelConnectionString, string[] sentinels, bool rw_splitting)
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public override void Refersh(IRedisSocket redisSocket)
public override IRedisSocket GetRedisSocket(CommandPacket cmd)
{
var poolkey = GetIdleBusKey(cmd);
if (string.IsNullOrWhiteSpace(poolkey)) throw new RedisClientException($"{_connectionString.Host}】Redis Sentinel is switching");
if (string.IsNullOrWhiteSpace(poolkey)) throw new RedisClientException($"{_connectionString.Host}】Redis Sentinel is switching{(_switchingException == null ? "" : $", {_switchingException.Message}")}");
var pool = _ib.Get(poolkey);
var cli = pool.Get();
var rds = cli.Value.Adapter.GetRedisSocket(null);
Expand Down Expand Up @@ -191,6 +192,7 @@ internal void ResetSentinel()
Interlocked.Decrement(ref ResetSentinelFlag);
return;
}
_switchingException = null;
string masterhostEnd = _masterHost;
var allkeys = _ib.GetKeys().ToList();

Expand Down Expand Up @@ -230,7 +232,10 @@ internal void ResetSentinel()
}
break;
}
catch { }
catch (Exception ex)
{
_switchingException = ex;
}
}

foreach (var spkey in allkeys) _ib.TryRemove(spkey, true);
Expand Down

0 comments on commit dc91206

Please sign in to comment.