Пример #1
0
        public static RedisMasterRoleSlaveInfo Parse(RedisRawObject rawObject)
        {
            if (!ReferenceEquals(rawObject, null) && rawObject.Type == RedisRawObjectType.Array)
            {
                var list = rawObject.Items;
                if (list != null)
                {
                    var count = list.Count;
                    if (count > 0)
                    {
                        var result = new RedisMasterRoleSlaveInfo();

                        var item = list[0];
                        if (!ReferenceEquals(item, null) && item.Type == RedisRawObjectType.BulkString)
                        {
                            result.IPAddress = item.DataText;
                        }

                        if (count > 1)
                        {
                            item = list[1];
                            if (!ReferenceEquals(item, null) && item.Type == RedisRawObjectType.BulkString)
                            {
                                var port = item.DataText;
                                if (!port.IsEmpty())
                                {
                                    int i;
                                    if (int.TryParse(port, out i))
                                    {
                                        result.Port = i;
                                    }
                                }
                            }

                            if (count > 2)
                            {
                                item = list[2];
                                if (!ReferenceEquals(item, null) && item.Type == RedisRawObjectType.BulkString)
                                {
                                    var offset = item.DataText;
                                    if (!offset.IsEmpty())
                                    {
                                        long l;
                                        if (long.TryParse(offset, out l))
                                        {
                                            result.ReplicationOffset = l;
                                        }
                                    }
                                }
                            }
                        }

                        return(result);
                    }
                }
            }
            return(null);
        }
Пример #2
0
        protected override void ParseInfo(RedisRawObject rawObject)
        {
            if (!ReferenceEquals(rawObject, null) && rawObject.Type == RedisRawObjectType.Array)
            {
                var list = rawObject.Items;
                if (list != null)
                {
                    var count = list.Count;
                    if (count > 1)
                    {
                        var item = list[1];
                        if (!ReferenceEquals(item, null) && item.Type == RedisRawObjectType.BulkString)
                        {
                            var data = item.Data;
                            if (data is long)
                            {
                                ReplicationOffset = (long)data;
                            }
                            else if (data is int)
                            {
                                ReplicationOffset = (int)data;
                            }
                        }

                        if (count > 2)
                        {
                            var slaves = new List <RedisMasterRoleSlaveInfo>(count - 2);
                            for (var i = 2; i < count; i++)
                            {
                                var slaveInfo = RedisMasterRoleSlaveInfo.Parse(list[i]);
                                if (slaveInfo != null)
                                {
                                    slaves.Add(slaveInfo);
                                }
                            }

                            if (slaves.Count > 0)
                            {
                                Slaves = slaves.ToArray();
                            }
                        }
                    }
                }
            }
        }