/// <summary>
        /// Event that is fired when the sentinel subscription raises an event
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="message"></param>
        private void SentinelMessageReceived(string channel, string message)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Received '{0}' on channel '{1}' from Sentinel".Fmt(channel, message));
            }

            // {+|-}sdown is the event for server coming up or down
            if ((channel == "+failover-end") || channel.ToLower().Contains("sdown"))
            {
                Log.Info("Sentinel detected server down/up with message:{0}".Fmt(message));

                ConfigureRedisFromSentinel();
            }

            if (redisSentinel.OnSentinelMessageReceived != null)
            {
                redisSentinel.OnSentinelMessageReceived(channel, message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event that is fired when the sentinel subscription raises an event
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="message"></param>
        private void SentinelMessageReceived(string channel, string message)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Received '{0}' on channel '{1}' from Sentinel".Fmt(channel, message));
            }

            // {+|-}sdown is the event for server coming up or down
            var c = channel.ToLower();
            var isSubjectivelyDown = c.Contains("sdown");

            if (isSubjectivelyDown)
            {
                Interlocked.Increment(ref RedisState.TotalSubjectiveServersDown);
            }

            var isObjectivelyDown = c.Contains("odown");

            if (isObjectivelyDown)
            {
                Interlocked.Increment(ref RedisState.TotalObjectiveServersDown);
            }

            if (c == "+failover-end" ||
                c == "+switch-master" ||
                (sentinel.ResetWhenSubjectivelyDown && isSubjectivelyDown) ||
                (sentinel.ResetWhenObjectivelyDown && isObjectivelyDown))
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("Sentinel detected server down/up '{0}' with message: {1}".Fmt(channel, message));
                }

                sentinel.ResetClients();
            }

            if (sentinel.OnSentinelMessageReceived != null)
            {
                sentinel.OnSentinelMessageReceived(channel, message);
            }
        }