Ejemplo n.º 1
0
            static Tuple <T1, T2> Create(RedisReader reader)
            {
                T1 item1 = (T1)converter1.Value.ConvertFromInvariantString(reader.ReadBulkString());
                T2 item2 = (T2)converter2.Value.ConvertFromInvariantString(reader.ReadBulkString());

                return(Tuple.Create(item1, item2));
            }
Ejemplo n.º 2
0
            public override DateTimeOffset Parse(RedisReader reader)
            {
                reader.ExpectType(RedisMessage.MultiBulk);
                reader.ExpectSize(2);

                int timestamp    = Int32.Parse(reader.ReadBulkString());
                int microseconds = Int32.Parse(reader.ReadBulkString());

                return(FromTimestamp(timestamp, microseconds));
            }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
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()));
        }
Ejemplo n.º 5
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()));
        }
Ejemplo n.º 6
0
        static RedisSubscriptionMessage ParseMessage(string type, RedisReader reader)
        {
            if (type == "message")
            {
                return(new RedisSubscriptionMessage(type, reader.ReadBulkString(), reader.ReadBulkString()));
            }

            else if (type == "pmessage")
            {
                return(new RedisSubscriptionMessage(type, reader.ReadBulkString(), reader.ReadBulkString(), reader.ReadBulkString()));
            }

            throw new RedisProtocolException("Unexpected type " + type);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public override string Parse(RedisReader reader)
 {
     if (IsNullable)
     {
         RedisMessage type = reader.ReadType();
         if (type == RedisMessage.Bulk)
         {
             return(reader.ReadBulkString(false));
         }
         reader.ReadMultiBulk(false);
         return(null);
     }
     else
     {
         return(reader.ReadBulkString());
     }
 }
Ejemplo n.º 9
0
            public override double?Parse(RedisReader reader)
            {
                string result = reader.ReadBulkString();

                if (result == null)
                {
                    return(null);
                }
                return(RedisFloat.FromString(result));
            }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        private static double?ParseStream(Stream stream)
        {
            string result = RedisReader.ReadBulkString(stream);

            if (result == null)
            {
                return(null);
            }
            return(Double.Parse(result, NumberStyles.Float));
        }
Ejemplo n.º 12
0
            public override decimal?Parse(RedisReader reader)
            {
                string result = reader.ReadBulkString();

                if (string.IsNullOrEmpty(result))
                {
                    return(null);
                }
                return(RedisFloat.FromString(result));
            }
        public override double?Parse(RedisReader reader)
        {
            string result = reader.ReadBulkString();

            if (result == null)
            {
                return(null);
            }
            return(double.Parse(result, NumberStyles.Float, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 14
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));
        }
Ejemplo n.º 15
0
 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));
 }
Ejemplo n.º 16
0
            public override long?Parse(RedisReader reader)
            {
                RedisMessage type = reader.ReadType();

                if (type == RedisMessage.Int)
                {
                    return(reader.ReadInt(false));
                }
                reader.ReadBulkString(false);
                return(null);
            }
Ejemplo n.º 17
0
        static Dictionary <string, string> ToDict(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);
        }
Ejemplo n.º 18
0
        private static string Read(Stream stream)
        {
            var type = RedisReader.ReadType(stream);

            if (type == RedisMessage.Bulk)
            {
                return(RedisReader.ReadBulkString(stream, false));
            }
            RedisReader.ReadMultiBulk(stream, false);
            return(null);
        }
Ejemplo n.º 19
0
        private static long?ParseStream(Stream stream)
        {
            RedisMessage type = RedisReader.ReadType(stream);

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

            RedisReader.ReadBulkString(stream, false);
            return(null);
        }
Ejemplo n.º 20
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));
        }
Ejemplo n.º 21
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));
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        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);
            }
        }
Ejemplo n.º 24
0
 public override double Parse(RedisReader reader)
 {
     return(FromString(reader.ReadBulkString()));
 }
 public override string Parse(RedisReader reader)
 {
     return(reader.ReadBulkString());
 }
 public override int Parse(RedisReader reader)
 {
     return(Int32.Parse(reader.ReadBulkString()));
 }
Ejemplo n.º 27
0
 private static double ParseStream(Stream stream)
 {
     return(Double.Parse(RedisReader.ReadBulkString(stream), NumberStyles.Float));
 }
 public override T Parse(RedisReader reader)
 {
     return((T)converter.Value.ConvertFromInvariantString(reader.ReadBulkString()));
 }
Ejemplo n.º 29
0
 public override Tuple <string, string> Parse(RedisReader reader)
 {
     reader.ExpectType(RedisMessage.MultiBulk);
     reader.ExpectSize(2);
     return(Tuple.Create(reader.ReadBulkString(), reader.ReadBulkString()));
 }