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));
        }
Ejemplo n.º 2
0
        public RedisPipelineTests()
        {
            _response    = RedisResponse.CreateStatus("OK", null);
            _redisSender = new Mock <IRedisSender>();
            _redisSender.Setup(c => c.BytesInBuffer).Returns(0);
            _redisSender.Setup(c => c.Send(It.IsAny <SenderAsyncEventArgs>()))
            .Callback((SenderAsyncEventArgs args) => args.Completed(args)).Returns(true);
            _redisSender.Setup(c => c.Flush(It.IsAny <SenderAsyncEventArgs>()))
            .Callback((SenderAsyncEventArgs args) =>
            {
                args.Completed(args);
            }).Returns(true);


            _redisReceiver = new Mock <IRedisReceiver>();

            _redisReceiver.Setup(c => c.Receive(It.IsAny <ReceiverAsyncEventArgs>()))
            .Callback((ReceiverAsyncEventArgs args) =>
            {
                args.Response = _response;
                args.Completed(args);
            }).Returns(true);
        }