StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

ConnectionRestored event always raised two times after Redis restart

Open Xiaohongt opened this issue 12 years ago • 2 comments

We use StackExchange.Redis in SignalR Redis scale-out, I found that ConnectionRestored event always raised two times after Redis restart.

Here is simple repro app:

       private static ConnectionMultiplexer _connection;
        static void Main(string[] args)
        {
           string connectionString = "......";
            _connection = ConnectionMultiplexer.Connect(connectionString);

            _connection.ConnectionRestored += OnConnectionRestored;

            Console.ReadLine();
        }

        private static void OnConnectionRestored(object sender, ConnectionFailedEventArgs args)
        {
            Console.WriteLine("_connection.IsConnected is " + _connection.IsConnected);
        }

Repro steps: 1). Update connectionString for your Redis, build the app and run 2). Stop and Restart the Redis

Expected result: OnConnectionRestored rasie one time, in output should just display one line "_connection.IsConnected is ..."

Actual result: OnConnectionRestored rasie two times, in output displays two lines "_connection.IsConnected is ..."

Xiaohongt avatar Jun 20 '14 21:06 Xiaohongt

At a guess, you'll probably find from the ConnectionFailedEventArgs object that one event is for the Interactive connection, and the other for the Subscription connection (assuming you are using pub/sub functionality in Redis).

Try changing your console printing line to:

Console.WriteLine("{0}: _connection.IsConnected is {1}", args.ConnectionType, _connection.IsConnected);

tekr avatar Aug 19 '14 06:08 tekr

Yep, the above comment is correct. Closing this out due to answered and age.

NickCraver avatar Jan 25 '16 15:01 NickCraver