Ejemplo n.º 1
0
        private bool ProcessRedisLine(bool async, AsyncSocketEventArgs args)
        {
            var lineValue = _lineBuffer.ToString();

            if (args.HasError)
            {
                return(ProcessRedisResponse(async, args));
            }

            if (_firstChar.IsErrorReply())
            {
                _redisResponse = RedisResponse.CreateError(lineValue, _serializer);
            }
            else if (_firstChar.IsStatusReply())
            {
                _redisResponse = RedisResponse.CreateStatus(lineValue, _serializer);
            }
            else if (_firstChar.IsIntReply())
            {
                _redisResponse = RedisResponse.CreateInteger(lineValue.ToInt(), _serializer);
            }
            else if (_firstChar.IsBulkReply())
            {
                var length = lineValue.ToInt();
                //check nil reply
                if (length < 0)
                {
                    _redisResponse = RedisResponse.CreateBulk(null, _serializer);
                }
                else if (length == 0)
                {
                    _redisResponse = RedisResponse.CreateBulk(new byte[0], _serializer);
                }
                else
                {
                    args.Completed = ProcessRedisBulkLine;
                    return(ReadBlockLine(length, args) || ProcessRedisBulkLine(async, args));
                }
            }
            else if (_firstChar.IsMultiBulkReply())
            {
                _multiBulkPartsLeft = lineValue.ToInt();

                if (_multiBulkPartsLeft == -1)                 // multi-bulk nill
                {
                    _redisResponse = RedisResponse.CreateMultiBulk(null, _serializer);
                }
                else
                {
                    _multiBulkParts = new RedisResponse[_multiBulkPartsLeft];

                    if (_multiBulkPartsLeft > 0)
                    {
                        return(ReadResponseFromStream(async, args));
                    }
                }
            }

            return(ProcessRedisResponse(async, args));
        }