예제 #1
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="seqId"></param>
 /// <param name="reply"></param>
 /// <exception cref="ArgumentNullException">reply is null.</exception>
 public RedisMessage(int seqId, IRedisReply reply)
 {
     if (reply == null)
     {
         throw new ArgumentNullException("reply");
     }
     this._seqId = seqId;
     this.Reply  = reply;
 }
예제 #2
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="seqID"></param>
 /// <param name="reply"></param>
 /// <exception cref="ArgumentNullException">reply is null.</exception>
 public RedisResponse(int seqID, IRedisReply reply)
 {
     if (reply == null)
     {
         throw new ArgumentNullException("reply");
     }
     this._seqID = seqID;
     this.Reply  = reply;
 }
예제 #3
0
        /// <summary>
        /// find multi-bulk reply
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="readlength"></param>
        /// <returns></returns>
        private MultiBulkReplies FindMultiBulk(ArraySegment <byte> buffer, out int readlength)
        {
            var prefixed = GetPrefixedLength(buffer);

            if (prefixed.OverIndex == -1)
            {
                readlength = 0; return(null);
            }

            if (prefixed.Value < 0)
            {
                readlength = prefixed.OverIndex + 1 - buffer.Offset;
                return(new MultiBulkReplies(null));
            }

            var totalReadlength = prefixed.OverIndex + 1 - buffer.Offset;
            var replies         = new IRedisReply[prefixed.Value];

            for (int i = 0, l = prefixed.Value; i < l; i++)
            {
                if (buffer.Count <= totalReadlength)
                {
                    readlength = 0; return(null);
                }

                int childReadLength = 0;
                var childBuffer     = new ArraySegment <byte>(buffer.Array, buffer.Offset + totalReadlength, buffer.Count - totalReadlength);

                IRedisReply reply = null;
                switch (childBuffer.Array[childBuffer.Offset])
                {
                case 43: reply = this.FindStatus(childBuffer, out childReadLength); break;       //'+'

                case 45: reply = this.FindError(childBuffer, out childReadLength); break;        //'-'

                case 58: reply = this.FindInteger(childBuffer, out childReadLength); break;      //':'

                case 36: reply = this.FindBulk(childBuffer, out childReadLength); break;         //'$'

                default: throw new BadProtocolException();
                }

                if (childReadLength < 1)
                {
                    readlength = 0; return(null);
                }

                replies[i]       = reply;
                totalReadlength += childReadLength;
            }

            readlength = totalReadlength;
            return(new MultiBulkReplies(replies));
        }
예제 #4
0
        /// <summary>
        /// find response
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="buffer"></param>
        /// <param name="readlength"></param>
        /// <returns></returns>
        /// <exception cref="BadProtocolException">未能识别的协议</exception>
        public RedisResponse FindResponse(IConnection connection, ArraySegment <byte> buffer, out int readlength)
        {
            IRedisReply reply = null;

            switch (buffer.Array[buffer.Offset])
            {
            case 43: reply = this.FindStatus(buffer, out readlength); break;        //'+'

            case 45: reply = this.FindError(buffer, out readlength); break;         //'-'

            case 58: reply = this.FindInteger(buffer, out readlength); break;       //':'

            case 36: reply = this.FindBulk(buffer, out readlength); break;          //'$'

            case 42: reply = this.FindMultiBulk(buffer, out readlength); break;     //'*'

            default: throw new BadProtocolException();
            }
            if (reply == null)
            {
                return(null);
            }
            return(new RedisResponse(GetSeqID(connection), reply));
        }
예제 #5
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="seqId"></param>
 /// <param name="reply"></param>
 /// <exception cref="ArgumentNullException">reply is null.</exception>
 public RedisMessage(int seqId, IRedisReply reply)
 {
     if (reply == null) throw new ArgumentNullException("reply");
     this._seqId = seqId;
     this.Reply = reply;
 }
예제 #6
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="replies"></param>
 public MultiBulkReplies(IRedisReply[] replies)
 {
     this.Replies = replies;
 }
예제 #7
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="seqID"></param>
 /// <param name="reply"></param>
 /// <exception cref="ArgumentNullException">reply is null.</exception>
 public RedisResponse(int seqID, IRedisReply reply)
 {
     if (reply == null) throw new ArgumentNullException("reply");
     this._seqID = seqID;
     this.Reply = reply;
 }