public Tuple <RedisManagedMSGroup, RedisManagedSentinelGroup> CreateGroups()
        {
            ValidateNotDisposed();

            var tuple = CreateGroupSockets();

            if (tuple != null)
            {
                RedisManagedSentinelGroup sentinels        = null;
                RedisManagedMSGroup       mastersAndSlaves = null;

                RedisManagedPoolGroup slaves  = null;
                RedisManagedPoolGroup masters = null;
                try
                {
                    masters = (RedisManagedPoolGroup)ToNodesGroup(RedisRole.Master, tuple.Masters);
                    try
                    {
                        slaves = (RedisManagedPoolGroup)ToNodesGroup(RedisRole.Slave, tuple.Slaves);
                        try
                        {
                            sentinels = (RedisManagedSentinelGroup)ToNodesGroup(RedisRole.Sentinel, tuple.Sentinels);
                        }
                        catch (Exception)
                        {
                            if (sentinels != null)
                            {
                                sentinels.Dispose();
                                sentinels = null;
                            }
                            throw;
                        }
                    }
                    catch (Exception)
                    {
                        if (slaves != null)
                        {
                            slaves.Dispose();
                            slaves = null;
                        }
                        throw;
                    }
                }
                catch (Exception)
                {
                    if (masters != null)
                    {
                        masters.Dispose();
                        masters = null;
                    }
                    throw;
                }

                mastersAndSlaves = new RedisManagedMSGroup((RedisManagerSettings)Settings, masters, slaves);
                return(new Tuple <RedisManagedMSGroup, RedisManagedSentinelGroup>(mastersAndSlaves, sentinels));
            }
            return(null);
        }
        public RedisManagedMSGroup(RedisManagerSettings settings,
                                   RedisManagedPoolGroup masters, RedisManagedPoolGroup slaves = null,
                                   Action <object, RedisCardioPulseStatus> onPulseStateChange  = null)
        {
            m_OnPulseStateChange         = onPulseStateChange;
            m_Settings                   = settings;
            m_UseSlaveAsMasterWhenNeeded = settings.UseSlaveAsMasterIfNoMasterFound;

            ExchangeSlavesInternal(slaves ?? new RedisManagedPoolGroup(settings, RedisRole.Slave, null, null));
            ExchangeMastersInternal(masters ?? new RedisManagedPoolGroup(settings, RedisRole.Master, null, null));
        }
        private RedisManagedPoolGroup ExchangeSlavesInternal(RedisManagedPoolGroup slaves)
        {
            lock (m_SyncRoot)
            {
                var oldGroup = Interlocked.Exchange(ref m_Slaves, slaves);
                if (oldGroup != null)
                {
                    oldGroup.SetOnPulseStateChange(null);
                }

                if (slaves != null)
                {
                    slaves.SetOnPulseStateChange(OnPulseStateChange);
                }

                return(oldGroup);
            }
        }
        private RedisManagedPoolGroup ExchangeMastersInternal(RedisManagedPoolGroup masters)
        {
            lock (m_SyncRoot)
            {
                var oldGroup = Interlocked.Exchange(ref m_Masters, masters);
                if (oldGroup != null)
                {
                    oldGroup.SetOnPulseStateChange(null);
                }

                if (masters != null)
                {
                    masters.SetOnPulseStateChange(OnPulseStateChange);
                }

                return(oldGroup);
            }
        }
 public RedisManagedPoolGroup ExchangeSlaves(RedisManagedPoolGroup slaves)
 {
     ValidateNotDisposed();
     return(ExchangeSlavesInternal(slaves));
 }
 public RedisManagedPoolGroup ExchangeMasters(RedisManagedPoolGroup masters)
 {
     ValidateNotDisposed();
     return(ExchangeMastersInternal(masters));
 }