Exemplo n.º 1
0
        public override object[] Parse(RedisReader reader)
        {
            if (_parsers.Count == 0)
            {
                return(reader.ReadMultiBulk(bulkAsString: true));
            }

            reader.ExpectType(RedisMessage.MultiBulk);
            long count = reader.ReadInt(false);

            if (count != _parsers.Count)
            {
                throw new RedisProtocolException(String.Format("Expecting {0} array items; got {1}", _parsers.Count, count));
            }

            object[] results = new object[_parsers.Count];
            for (int i = 0; i < results.Length; i++)
            {
                results[i] = _parsers.Dequeue()(reader);
            }
            return(results);
        }
        public override RedisRole Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            int count = (int)reader.ReadInt(false);

            string role = reader.ReadBulkString();

            switch (role)
            {
            case "master":
                return(ParseMaster(count, role, reader));

            case "slave":
                return(ParseSlave(count, role, reader));

            case "sentinel":
                return(ParseSentinel(count, role, reader));

            default:
                throw new RedisProtocolException("Unexpected role: " + role);
            }
        }
Exemplo n.º 3
0
        object[] ReadTransaction(Stream input)
        {
            if (!_captureResults)
            {
                RedisObjects command = RedisCommand.Exec();
                command.Parser(input);
                return(null);
            }

            RedisReader.ExpectType(input, RedisMessage.MultiBulk);
            long count = RedisReader.ReadInt(input, false);

            if (count == -1)
            {
                return(null);
            }

            object[] output = new object[_parsers.Count];
            for (int i = 0; i < output.Length; i++)
            {
                output[i] = _connection.Read(_parsers.Dequeue());
            }
            return(output);
        }
Exemplo n.º 4
0
 public override Tuple <string, string> Parse(RedisReader reader)
 {
     reader.ExpectType(RedisMessage.MultiBulk);
     reader.ExpectSize(2);
     return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString()));
 }
Exemplo n.º 5
0
 public void Read(Stream destination, int bufferSize)
 {
     _reader.ExpectType(RedisMessage.Bulk);
     _reader.ReadBulk(destination, bufferSize, false);
 }