예제 #1
0
        /// <summary>
        /// Read multi-bulk response from Redis server
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static RedisSubscriptionResponse ReadResponse(object[] response)
        {
            RedisSubscriptionResponseType type = ParseType(response[0] as String);

            RedisSubscriptionResponse obj;

            switch (type)
            {
            case RedisSubscriptionResponseType.Subscribe:
            case RedisSubscriptionResponseType.Unsubscribe:
            case RedisSubscriptionResponseType.PSubscribe:
            case RedisSubscriptionResponseType.PUnsubscribe:
                obj = new RedisSubscriptionChannel(type, response);
                break;

            case RedisSubscriptionResponseType.Message:
            case RedisSubscriptionResponseType.PMessage:
                obj = new RedisSubscriptionMessage(type, response);
                break;

            default:
                throw new RedisProtocolException("Unexpected response type: " + type);
            }
            obj.Type = type;
            return(obj);
        }
예제 #2
0
 public void OnMsgReceived(RedisSubscriptionMessage message)
 {
     if (MessageReceived != null)
     {
         MessageReceived(null, new RedisSubscriptionReceivedEventArgs(message));
     }
 }
예제 #3
0
        private void Read_Task()
        {
            RedisSubscriptionResponse response;

            using (new ActivityTracer("Handle subscriptions"))
            {
                while (true)
                {
                    if (_readCancel.IsCancellationRequested)
                    {
                        break;
                    }

                    response = TryReadResponse();
                    if (response == null)
                    {
                        continue;
                    }

                    switch (response.Type)
                    {
                    case RedisSubscriptionResponseType.Subscribe:
                    case RedisSubscriptionResponseType.PSubscribe:
                    case RedisSubscriptionResponseType.Unsubscribe:
                    case RedisSubscriptionResponseType.PUnsubscribe:
                        RedisSubscriptionChannel channel = response as RedisSubscriptionChannel;
                        Interlocked.Exchange(ref _count, channel.Count);
                        if (SubscriptionChanged != null)
                        {
                            SubscriptionChanged(this, new RedisSubscriptionChangedEventArgs(channel));
                        }
                        break;

                    case RedisSubscriptionResponseType.Message:
                    case RedisSubscriptionResponseType.PMessage:
                        RedisSubscriptionMessage message = response as RedisSubscriptionMessage;
                        if (SubscriptionReceived != null)
                        {
                            SubscriptionReceived(this, new RedisSubscriptionReceivedEventArgs(message));
                        }

                        if (message.Pattern != null && _callbackDispatchers.ContainsKey(message.Pattern) && _callbackDispatchers[message.Pattern] != null)
                        {
                            _callbackDispatchers[message.Pattern].OnMsgReceived(message);
                        }
                        else if (_callbackDispatchers.ContainsKey(message.Channel) && _callbackDispatchers[message.Channel] != null)
                        {
                            _callbackDispatchers[message.Channel].OnMsgReceived(message);
                        }
                        break;
                    }
                }
            }
        }
예제 #4
0
        public void HandleSubscription(RedisSubscription command)
        {
            _connection.Write(command.Command, command.Arguments);
            if (!IsSubscribed)
            {
                using (new ActivityTracer("Handle subscriptions"))
                {
                    IsSubscribed = true;
                    while (true)
                    {
                        var resp = _connection.Read(command.Parser);
                        switch (resp.Type)
                        {
                        case RedisSubscriptionResponseType.Subscribe:
                        case RedisSubscriptionResponseType.PSubscribe:
                        case RedisSubscriptionResponseType.Unsubscribe:
                        case RedisSubscriptionResponseType.PUnsubscribe:
                            RedisSubscriptionChannel channel = resp as RedisSubscriptionChannel;
                            Count = channel.Count;
                            if (SubscriptionChanged != null)
                            {
                                SubscriptionChanged(this, new RedisSubscriptionChangedEventArgs(channel));
                            }
                            break;

                        case RedisSubscriptionResponseType.Message:
                        case RedisSubscriptionResponseType.PMessage:
                            RedisSubscriptionMessage message = resp as RedisSubscriptionMessage;
                            if (SubscriptionReceived != null)
                            {
                                SubscriptionReceived(this, new RedisSubscriptionReceivedEventArgs(message));
                            }
                            break;
                        }
                        if (Count == 0)
                        {
                            break;
                        }
                    }
                    IsSubscribed = false;
                }
            }
        }
예제 #5
0
 public void OnMsgReceived(RedisSubscriptionMessage message)
 {
     if (MessageReceived != null)
         MessageReceived(null, new RedisSubscriptionReceivedEventArgs(message));
 }
예제 #6
0
        /// <summary>
        /// Read multi-bulk response from Redis server
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static RedisSubscriptionResponse ReadResponse(object[] response)
        {
            RedisSubscriptionResponseType type  = ParseType(response[0] as String);

            RedisSubscriptionResponse obj;
            switch (type)
            {
                case RedisSubscriptionResponseType.Subscribe:
                case RedisSubscriptionResponseType.Unsubscribe:
                case RedisSubscriptionResponseType.PSubscribe:
                case RedisSubscriptionResponseType.PUnsubscribe:
                    obj = new RedisSubscriptionChannel(type, response);
                    break;

                case RedisSubscriptionResponseType.Message:
                case RedisSubscriptionResponseType.PMessage:
                    obj = new RedisSubscriptionMessage(type, response);
                    break;

                default:
                    throw new RedisProtocolException("Unexpected response type: " + type);
            }
            obj.Type = type;
            return obj;
        }
예제 #7
0
파일: Events.cs 프로젝트: bapti/csredis
 /// <summary>
 /// Instantiate a new instance of the RedisSubscriptionReceivedEventArgs class
 /// </summary>
 /// <param name="message">The Redis server message</param>
 public RedisSubscriptionReceivedEventArgs(RedisSubscriptionMessage message)
 {
     Message = message;
 }
예제 #8
0
 /// <summary>
 /// Instantiate a new instance of the RedisSubscriptionReceivedEventArgs class
 /// </summary>
 /// <param name="message">The Redis server message</param>
 public RedisSubscriptionReceivedEventArgs(RedisSubscriptionMessage message)
 {
     Message = message;
 }