我们正在使用StackExchange.Redis ConnectionMultiplexer类,如下所示:
private void InitializeConnection()
{
_logger.Info("Initializing a connection to the Redis cluster. ");
bool isReconnectionAttempt = false;
if (_connectionMultiplexer != null)
{
Debug.WriteLine("disposing " + _connectionMultiplexer.GetHashCode());
_connectionMultiplexer.ConnectionFailed -= HandleConnectionFailedEvent;
// test this change.....
_connectionMultiplexer.Close();
isReconnectionAttempt = true;
_logger.Info("This is reconnection attempt to the Redis cluster.");
}
_connectionMultiplexer = ConnectionMultiplexer.Connect(_connectionString);
_needConnect = !_connectionMultiplexer.IsConnected;
_connectionMultiplexer.ConnectionFailed += HandleConnectionFailedEvent;
当我模拟网络问题时,会按预期触发ConnectionFailed事件。发生这种情况时,我们会尝试处理对象并创建一个新对象。但是,即使在前一个_connectionMultiplexer实例被关闭/处理之后,我们仍然会获得前一个实例触发的几个ConnectionFailed事件。
但是,该文档表明,当网络出现故障时,我们只会收到一个ConnectionFailed事件。下次我们得到这样的事件时,网络再次出现故障。但这不是我所经历的。想法?