static RedisSlaveRole ParseSlave(int num, string role, RedisReader reader)
        {
            reader.ExpectSize(5, num);
            string master_ip = reader.ReadBulkString();
            int    port      = (int)reader.ReadInt();
            string state     = reader.ReadBulkString();
            long   data      = reader.ReadInt();

            return(new RedisSlaveRole(role, master_ip, port, state, data));
        }
Exemple #2
0
        public override RedisMasterState Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            reader.ExpectSize(3);
            long   down_state = reader.ReadInt();
            string leader     = reader.ReadBulkString();
            long   vote_epoch = reader.ReadInt();

            return(new RedisMasterState(down_state, leader, vote_epoch));
        }
Exemple #3
0
            public override T[] Parse(RedisReader reader)
            {
                reader.ExpectType(RedisMessage.MultiBulk);
                long count = reader.ReadInt(false);

                return(Read(count, reader));
            }
Exemple #4
0
        public override RedisSlowLogEntry Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            reader.ExpectSize(4);
            long id           = reader.ReadInt();
            long timestamp    = reader.ReadInt();
            long microseconds = reader.ReadInt();

            reader.ExpectType(RedisMessage.MultiBulk);
            string[] arguments = new string[reader.ReadInt(false)];
            for (int i = 0; i < arguments.Length; i++)
            {
                arguments[i] = reader.ReadBulkString();
            }

            return(new RedisSlowLogEntry(id, RedisDate.FromTimestamp(timestamp), RedisDate.Micro.FromMicroseconds(microseconds), arguments));
        }
        static RedisMasterRole ParseMaster(int num, string role, RedisReader reader)
        {
            reader.ExpectSize(3, num);
            long offset = reader.ReadInt();

            reader.ExpectType(RedisMessage.MultiBulk);
            var slaves = new Tuple <string, int, int> [reader.ReadInt(false)];

            for (int i = 0; i < slaves.Length; i++)
            {
                reader.ExpectType(RedisMessage.MultiBulk);
                reader.ExpectSize(3);
                string ip           = reader.ReadBulkString();
                int    port         = Int32.Parse(reader.ReadBulkString());
                int    slave_offset = Int32.Parse(reader.ReadBulkString());
                slaves[i] = new Tuple <string, int, int>(ip, port, slave_offset);
            }
            return(new RedisMasterRole(role, offset, slaves));
        }
Exemple #6
0
            public override long?Parse(RedisReader reader)
            {
                RedisMessage type = reader.ReadType();

                if (type == RedisMessage.Int)
                {
                    return(reader.ReadInt(false));
                }
                reader.ReadBulkString(false);
                return(null);
            }
 static RedisSentinelRole ParseSentinel(int num, string role, RedisReader reader)
 {
     reader.ExpectSize(2, num);
     reader.ExpectType(RedisMessage.MultiBulk);
     string[] masters = new string[reader.ReadInt(false)];
     for (int i = 0; i < masters.Length; i++)
     {
         masters[i] = reader.ReadBulkString();
     }
     return(new RedisSentinelRole(role, masters));
 }
Exemple #8
0
        public override Tuple <string, string> Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            long count = reader.ReadInt(false);

            if (count != 2)
            {
                throw new RedisProtocolException("Expected 2 items");
            }
            return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString()));
        }
Exemple #9
0
            public override T Parse(RedisReader reader)
            {
                reader.ExpectType(RedisMessage.MultiBulk);
                long count = reader.ReadInt(false);

                T[] array = new T[count];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = _command.Parse(reader);
                }
                return(array[_index]);
            }
Exemple #10
0
        public override Tuple <string, string> Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            long count = reader.ReadInt(false);

            if (count != 2)
            {
                return(null);                        //使用 BLPop 命令在 RedisArray.cs 中报错的解决办法。 #22
            }
            //reader.ExpectSize(2);
            return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString()));
        }
        private static long?ParseStream(Stream stream)
        {
            RedisMessage type = RedisReader.ReadType(stream);

            if (type == RedisMessage.Int)
            {
                return(RedisReader.ReadInt(stream, false));
            }

            RedisReader.ReadBulkUTF8(stream, false);
            return(null);
        }
Exemple #12
0
        public override RedisScan <T> Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            if (reader.ReadInt(false) != 2)
            {
                throw new RedisProtocolException("Expected 2 items");
            }

            long cursor = Int64.Parse(reader.ReadBulkString());

            T[] items = _command.Parse(reader);

            return(new RedisScan <T>(cursor, items));
        }
Exemple #13
0
            public override T Parse(RedisReader reader)
            {
                reader.ExpectType(RedisMessage.MultiBulk);
                long count = reader.ReadInt(false);

                if (count == -1)
                {
                    return(default(T));             //使用 BLPop 命令在 RedisArray.cs 中报错的解决办法。 #22
                }
                T[] array = new T[count];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = _command.Parse(reader);
                }
                return(array[_index]);
            }
Exemple #14
0
        static RedisScan ParseStream(Stream stream)
        {
            RedisReader.ExpectType(stream, RedisMessage.MultiBulk);

            long      count = RedisReader.ReadInt(stream, false);
            RedisScan scan  = new RedisScan();

            scan.Cursor = Int64.Parse(RedisReader.Read(stream).ToString());
            RedisReader.ExpectType(stream, RedisMessage.MultiBulk);

            scan.Items = new string[RedisReader.ReadInt(stream, false)];
            for (int i = 0; i < scan.Items.Length; i++)
            {
                scan.Items[i] = RedisReader.Read(stream).ToString();
            }
            return(scan);
        }
        public override Dictionary <string, string> Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            long   count = reader.ReadInt(false);
            var    dict  = new Dictionary <string, string>();
            string key   = string.Empty;

            for (int i = 0; i < count; i++)
            {
                if (i % 2 == 0)
                {
                    key = reader.ReadBulkString();
                }
                else
                {
                    dict[key] = reader.ReadBulkString();
                }
            }
            return(dict);
        }
Exemple #16
0
        static Dictionary <string, byte[]> ToDict(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            long   count = reader.ReadInt(false);
            var    dict  = new Dictionary <string, byte[]>();
            string key   = String.Empty;

            for (int i = 0; i < count; i++)
            {
                if (i % 2 == 0)
                {
                    key = reader.ReadBulkString();
                }
                else
                {
                    dict[key] = reader.ReadBulkBytes();
                }
            }
            return(dict);
        }
Exemple #17
0
        public override RedisSubscriptionResponse Parse(RedisReader reader)
        {
            reader.ExpectType(RedisMessage.MultiBulk);
            long   count = reader.ReadInt(false);
            string type  = reader.ReadBulkString();

            switch (type)
            {
            case "subscribe":
            case "unsubscribe":
            case "psubscribe":
            case "punsubscribe":
                return(ParseChannel(type, reader));

            case "message":
            case "pmessage":
                return(ParseMessage(type, reader));
            }

            throw new RedisProtocolException("Unexpected type " + type);
        }
Exemple #18
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);
            }
        }
Exemple #20
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);
        }
Exemple #21
0
 private static bool ParseStream(Stream stream)
 {
     return(RedisReader.ReadInt(stream) == 1);
 }
Exemple #22
0
 public override long Parse(RedisReader reader)
 {
     return(reader.ReadInt());
 }
Exemple #23
0
        private static DateTime ParseStream(Stream stream)
        {
            long timestamp = RedisReader.ReadInt(stream);

            return(RedisArgs.Epoch + TimeSpan.FromSeconds(timestamp));
        }
Exemple #24
0
        static RedisSubscriptionChannel ParseChannel(string type, RedisReader reader)
        {
            switch (type)
            {
            case "subscribe":
            case "unsubscribe":
                return(new RedisSubscriptionChannel(type, reader.ReadBulkString(), null, reader.ReadInt()));

            case "psubscribe":
            case "punsubscribe":
                return(new RedisSubscriptionChannel(type, null, reader.ReadBulkString(), reader.ReadInt()));
            }

            throw new RedisProtocolException("Unexpected type " + type);
        }
Exemple #25
0
 public override DateTimeOffset Parse(RedisReader reader)
 {
     return(FromTimestamp(reader.ReadInt()));
 }
 public override bool Parse(RedisReader reader)
 {
     return(reader.ReadInt() == 1);
 }