Example #1
0
        internal RedisData ReadComplexResponse()
        {
            int c = SafeReadByte();

            if (c == -1)
            {
                throw CreateNoMoreDataError();
            }

            var s = ReadLine();

            if (log.IsDebugEnabled)
            {
                Log("R: {0}", s);
            }

            switch (c)
            {
            case '$':
                return(new RedisData
                {
                    Data = ParseSingleLine(string.Concat(char.ToString((char)c), s))
                });

            case '-':
                throw CreateResponseError(s.StartsWith("ERR") ? s.Substring(4) : s);

            case '*':
                int count;
                if (int.TryParse(s, out count))
                {
                    var ret = new RedisData {
                        Children = new List <RedisData>()
                    };
                    for (var i = 0; i < count; i++)
                    {
                        ret.Children.Add(ReadComplexResponse());
                    }

                    return(ret);
                }
                break;

            default:
                return(new RedisData {
                    Data = s.ToUtf8Bytes()
                });
            }

            throw CreateResponseError("Unknown reply on multi-request: " + c + s);
        }
Example #2
0
        public static RedisText ToRedisText(this RedisData data)
        {
            var to = new RedisText();

            if (data.Data != null)
            {
                to.Text = data.Data.FromUtf8Bytes();
            }

            if (data.Children != null)
            {
                to.Children = data.Children.ConvertAll(x => x.ToRedisText());
            }

            return(to);
        }