예제 #1
0
        }                                                                                  // 0

        #endregion Properties

        #region Methods

        public static RedisSentinelNodeInfo[] ParseInfoResponse(RedisArray array)
        {
            if (!ReferenceEquals(array, null))
            {
                var items = array.Value;
                if (items != null)
                {
                    var count = items.Count;
                    if (count > 0)
                    {
                        var isInfoArray = true;
                        for (var i = 0; i < count; i++)
                        {
                            var item = items[i];
                            if (!ReferenceEquals(item, null) &&
                                item.Type != RedisResultType.Array)
                            {
                                isInfoArray = false;
                                break;
                            }
                        }

                        if (!isInfoArray)
                        {
                            var info = new RedisSentinelNodeInfo(array);
                            return(new[] { info });
                        }

                        var list = new List <RedisSentinelNodeInfo>(count);
                        for (var i = 0; i < count; i++)
                        {
                            var item = items[i];
                            if (!ReferenceEquals(item, null) && item.Type == RedisResultType.Array)
                            {
                                var info = new RedisSentinelNodeInfo((RedisArray)item);
                                list.Add(info);
                            }
                        }

                        if (list.Count > 0)
                        {
                            return(list.ToArray());
                        }
                    }
                }
            }
            return(null);
        }
예제 #2
0
        private NodeRoleAndSiblings GetSiblingSentinelsOfSentinel(string masterName, RedisAsyncClient client)
        {
            if (masterName.IsEmpty())
            {
                throw new ArgumentNullException("masterName");
            }

            try
            {
                var response = client.Expect(new RedisCommand(-1, RedisCommandList.Sentinel, RedisCommandType.SendAndReceive,
                                                              RedisCommandList.Sentinels, masterName.ToBytes()));

                if (!ReferenceEquals(response, null) && response.Type == RedisResultType.Array)
                {
                    var result = response as RedisArray;
                    if (!ReferenceEquals(result, null))
                    {
                        var sentinelInfos = RedisSentinelNodeInfo.ParseInfoResponse(result);
                        if (sentinelInfos != null)
                        {
                            var length = sentinelInfos.Length;
                            if (length > 0)
                            {
                                var siblingEndPoints = new List <RedisEndPoint>(length);
                                for (var i = 0; i < length; i++)
                                {
                                    var sentinelInfo = sentinelInfos[i];

                                    if (!Disposed && sentinelInfo != null && sentinelInfo.Port.HasValue && !sentinelInfo.IPAddress.IsEmpty())
                                    {
                                        siblingEndPoints.Add(new RedisEndPoint(sentinelInfo.IPAddress, (int)sentinelInfo.Port.Value));
                                    }
                                }

                                if (!Disposed)
                                {
                                    return(new NodeRoleAndSiblings(RedisRole.Sentinel, siblingEndPoints.ToArray()));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            { }
            return(null);
        }
        public RedisResult <RedisSentinelNodeInfo[]> Sentinels(string masterName)
        {
            if (masterName.IsEmpty())
            {
                throw new ArgumentNullException("masterName");
            }

            var array = ExpectArray(new RedisCommand(RedisConstants.UninitializedDbIndex, RedisCommandList.Sentinel, RedisCommandList.Sentinels, masterName.ToBytes()));

            if (!ReferenceEquals(array, null))
            {
                var items = RedisSentinelNodeInfo.ParseInfoResponse(array);
                if (!items.IsEmpty())
                {
                    return(new RedisResult <RedisSentinelNodeInfo[]>(items));
                }
            }
            return(new RedisResult <RedisSentinelNodeInfo[]>(null));
        }