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);
        }
Beispiel #2
0
 public RedisManagedSentinelNode(RedisManagerSettings settings, RedisManagedSentinelListener listener,
                                 Action <object, RedisCardioPulseStatus> onPulseStateChange, bool ownsSeed = true)
     : base(settings, RedisRole.Sentinel, listener, onPulseStateChange, ownsSeed)
 {
     m_EndPoint = (listener != null) ? listener.EndPoint : RedisEndPoint.Empty;
 }