Esempio n. 1
0
            public SentinelAdapter(RedisClient topOwner, ConnectionStringBuilder sentinelConnectionString, string[] sentinels, bool rw_splitting)
            {
                UseType           = UseType.Sentinel;
                TopOwner          = topOwner;
                _connectionString = sentinelConnectionString;
                _sentinels        = new LinkedList <ConnectionStringBuilder>(sentinels?.Select(a =>
                {
                    var csb  = ConnectionStringBuilder.Parse(a);
                    csb.Host = csb.Host.ToLower();
                    return(csb);
                }).GroupBy(a => a.Host, a => a).Select(a => a.First()) ?? new ConnectionStringBuilder[0]);
                _rw_splitting = rw_splitting;

                _is_single = !_rw_splitting && sentinelConnectionString.MaxPoolSize == 1;
                if (_sentinels.Any() == false)
                {
                    throw new ArgumentNullException(nameof(sentinels));
                }

                _ib = new IdleBus <RedisClientPool>(TimeSpan.FromMinutes(10));
                ResetSentinel();

#if isasync
                _asyncManager = new AsyncRedisSocket.Manager(this);
#endif
            }
Esempio n. 2
0
            public PoolingAdapter(RedisClient topOwner, ConnectionStringBuilder connectionString, params ConnectionStringBuilder[] slaveConnectionStrings)
            {
                UseType       = UseType.Pooling;
                TopOwner      = topOwner;
                _masterHost   = connectionString.Host;
                _rw_splitting = slaveConnectionStrings?.Any() == true;
                _is_single    = !_rw_splitting && connectionString.MaxPoolSize == 1;

                _ib = new IdleBus <RedisClientPool>(TimeSpan.FromMinutes(10));
                _ib.Register(_masterHost, () => new RedisClientPool(connectionString, null, TopOwner));

                if (_rw_splitting)
                {
                    foreach (var slave in slaveConnectionStrings)
                    {
                        _ib.TryRegister($"slave_{slave.Host}", () => new RedisClientPool(slave, null, TopOwner));
                    }
                }

#if isasync
                _asyncManager = new AsyncRedisSocket.Manager(this);
#endif
            }