public IEnumerable <RESPCommand> Execute()
        {
            _tracker = _subscriptions.RemoveChannel(_channel);
            if (_tracker == null)
            {
                yield break;
            }

            foreach (var cmd in _tracker.GetCommands())
            {
                yield return(cmd);
            }
        }
Пример #2
0
        internal SubscriptionResponsesTracker RemoveChannel(IRedisChannel channel)
        {
            SubscriptionResponsesTracker tracker = new SubscriptionResponsesTracker();

            var keys = _subscriptions.GetSubscriptions(channel).ToList();

            if (keys.Any())
            {
                GenerateTracker(channel, tracker, "UNSUBSCRIBE", keys);
            }

            keys = _psubscriptions.GetSubscriptions(channel).ToList();
            if (keys.Any())
            {
                GenerateTracker(channel, tracker, "PUNSUBSCRIBE", keys);
            }

            return(tracker);
        }
Пример #3
0
        internal SubscriptionResponsesTracker Aggregate(IRedisChannel channel, IEnumerable <RESPCommand> commands)
        {
            Contract.Assert(commands.Any(), "Trying to track an empty list of commands.");

            var data = new SubscriptionResponsesTracker();

            foreach (var command in commands)
            {
                var operation = command.Header.ToUpperInvariant();
                var keys      = command.Skip(1).Cast <RESPCommandPart>().Select(x => x.Value).ToList();

                if (IsSubscriptionMessage(operation))
                {
                    throw new InvalidOperationException("Redis Messages are not subscription control operations.");
                }

                GenerateTracker(channel, data, operation, keys);
            }

            return(data);
        }
Пример #4
0
        private void GenerateTracker(IRedisChannel channel, SubscriptionResponsesTracker data, String operation, IList <string> keys)
        {
            switch (operation)
            {
            case "SUBSCRIBE":
                Include(operation, _subscriptions.Subscribe(channel, keys), data.AddSubscription, data.AddCommand);
                break;

            case "PSUBSCRIBE":
                Include(operation, _psubscriptions.Subscribe(channel, keys), data.AddSubscription, data.AddCommand);
                break;

            case "UNSUBSCRIBE":
                Include(operation, _subscriptions.Unsubscribe(channel, keys), data.AddUnsubscription, data.AddCommand);
                break;

            case "PUNSUBSCRIBE":
                Include(operation, _psubscriptions.Unsubscribe(channel, keys), data.AddUnsubscription, data.AddCommand);
                break;

            default: throw new InvalidOperationException("Unrecognized subscription control operation: " + operation);
            }
        }
Пример #5
0
 public IEnumerable <RESPCommand> Execute()
 {
     _tracker = _subscriptions.Aggregate(_channel, _commands.Where((c, i) => _commands[i].IsSubscription));
     return(_tracker.GetCommands());
 }