Esempio n. 1
0
        private void Subscribe()
        {
            this.redisSubscriper.Subscribe(
                this.channelName,
                (channel, msg) =>
            {
                string messageStr = (string)msg;

                if (messageStr.StartsWith(this.identifier, StringComparison.Ordinal))
                {
                    // do not notify ourself (might be faster than the second method?
                    return;
                }

                var message = BackPlateMessage.Deserialize(messageStr);

                switch (message.Action)
                {
                case BackPlateAction.Clear:
                    this.OnClear();
                    break;

                case BackPlateAction.ClearRegion:
                    this.OnClearRegion(message.Region);
                    break;

                case BackPlateAction.Changed:
                    if (string.IsNullOrWhiteSpace(message.Region))
                    {
                        this.OnChange(message.Key);
                    }
                    else
                    {
                        this.OnChange(message.Key, message.Region);
                    }
                    break;

                case BackPlateAction.Removed:
                    if (string.IsNullOrWhiteSpace(message.Region))
                    {
                        this.OnRemove(message.Key);
                    }
                    else
                    {
                        this.OnRemove(message.Key, message.Region);
                    }
                    break;
                }
            },
                StackRedis.CommandFlags.FireAndForget);
        }
Esempio n. 2
0
        private void Subscribe()
        {
            this.redisSubscriper.Subscribe(
                this.channelName,
                (channel, msg) =>
            {
                var fullMessage = ((string)msg).Split(',')
                                  .Where(s => !s.StartsWith(this.identifier, StringComparison.Ordinal))
                                  .ToArray();

                if (fullMessage.Length == 0)
                {
                    // no messages for this instance
                    return;
                }

                if (this.logger.IsEnabled(LogLevel.Information))
                {
                    this.logger.LogInfo("Back-plate got notified with {0} new messages.", fullMessage.Length);
                }

                foreach (var messageStr in fullMessage)
                {
                    var message = BackPlateMessage.Deserialize(messageStr);

                    switch (message.Action)
                    {
                    case BackPlateAction.Clear:
                        this.OnClear();
                        break;

                    case BackPlateAction.ClearRegion:
                        this.OnClearRegion(message.Region);
                        break;

                    case BackPlateAction.Changed:
                        if (string.IsNullOrWhiteSpace(message.Region))
                        {
                            this.OnChange(message.Key);
                        }
                        else
                        {
                            this.OnChange(message.Key, message.Region);
                        }
                        break;

                    case BackPlateAction.Removed:
                        if (string.IsNullOrWhiteSpace(message.Region))
                        {
                            this.OnRemove(message.Key);
                        }
                        else
                        {
                            this.OnRemove(message.Key, message.Region);
                        }
                        break;
                    }
                }
            },
                StackRedis.CommandFlags.FireAndForget);
        }