Redis StackExchange ConnectionMultiplexer连接事件触发两次

时间:2018-03-07 07:16:05

标签: c# stackexchange.redis eventhandler

我正在使用Redis StackExchange ConnectionMultiplexer与服务器建立连接。 我想在连接断开/恢复时记录连接活动的更改。但不知何故,当触发时事件会触发两次,这会在我的日志中产生重复的消息。

    ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(new ConfigurationOptions()
    {
        EndPoints = { "localhost" },
        AbortOnConnectFail = false
    });            

    connection.ConnectionFailed += (sender, args) =>
    {
        Console.WriteLine("Connection failed ");
    };

    connection.ConnectionRestored += (sender, args) =>
    {
        Console.WriteLine("Connection restored "); 
    };

我的问题是

  1. 为什么ConnectionFailed&触发后ConnectionRestored次事件会触发两次?
  2. 如何防止事件发生两次?

0 个答案:

没有答案