Esempio n. 1
0
        public RedisManagedPoolNode(RedisManagerSettings settings, RedisRole role, RedisManagedPool pool,
                                    Action <object, RedisCardioPulseStatus> onPulseStateChange, bool ownsSeed = true)
            : base(settings, role, pool, onPulseStateChange, ownsSeed)
        {
            m_EndPoint = (pool != null) ? pool.EndPoint : RedisEndPoint.Empty;

            if (pool != null)
            {
                pool.PoolPulseStateChanged   += OnPoolPulseStateChange;
                pool.PubSubPulseStateChanged += OnPubSubPulseStateChange;
            }
        }
        private RedisManagedNodesGroup ToNodesGroup(RedisRole role, RedisSocket[] sockets)
        {
            if (!sockets.IsEmpty())
            {
                var baseSettings = Settings;
                var nodeList     = new List <RedisManagedNode>();
                foreach (var socket in sockets)
                {
                    try
                    {
                        if (socket.IsConnected())
                        {
                            var endPoint = socket.RemoteEP;
                            var settings = (RedisManagerSettings)baseSettings.Clone(endPoint.Address.ToString(), endPoint.Port);

                            if (role == RedisRole.Sentinel)
                            {
                                var listener = new RedisManagedSentinelListener(settings, null, null);
                                listener.ReuseSocket(socket);

                                nodeList.Add(new RedisManagedSentinelNode(settings, listener, null));
                            }
                            else
                            {
                                var pool = new RedisManagedPool(role, Name, settings);
                                pool.ReuseSocket(socket);

                                nodeList.Add(new RedisManagedPoolNode(settings, role, pool, null));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        socket.DisposeSocket();
                    }
                }

                if (nodeList.Count > 0)
                {
                    var settings = (RedisManagerSettings)Settings;

                    return(role != RedisRole.Sentinel ?
                           (RedisManagedNodesGroup)(new RedisManagedPoolGroup(settings, role, nodeList.Cast <RedisManagedPoolNode>().ToArray(), null)) :
                           new RedisManagedSentinelGroup(settings, settings.MasterName, nodeList.Cast <RedisManagedSentinelNode>().ToArray(), null));
                }
            }
            return(null);
        }