Esempio n. 1
0
        protected override void OnConnectionRetry(RedisConnectionRetryEventArgs e)
        {
            var settings = Settings;

            if (!m_UseAsyncCompleter)
            {
                e.ThrowError     = true;
                e.ContinueToSpin = true;
            }
            else if (e.CurrentRetryCount > 0)
            {
                e.ThrowError     = false;
                e.ContinueToSpin = false;
            }
        }
Esempio n. 2
0
 protected virtual void OnConnectionTimeout(RedisConnectionRetryEventArgs e)
 {
 }
Esempio n. 3
0
        protected internal override IRedisConnection Connect(int dbIndex, RedisRole expectedRole)
        {
            ValidateNotDisposed();

            OnBeforeConnect(dbIndex, expectedRole);

            var settings = (Settings ?? RedisPoolSettings.Default);

            var spinStepTimeoutMs = GetConnectionSpinStepTimeout();

            var connectionTimeout = settings.ConnectionTimeout;

            connectionTimeout = connectionTimeout <= 0 ? RedisConstants.MaxConnectionTimeout : connectionTimeout;

            var retryCountLimit = (int)Math.Ceiling((double)settings.ConnectionWaitTimeout / spinStepTimeoutMs);
            var retryInfo       = new RedisConnectionRetryEventArgs(retryCountLimit, spinStepTimeoutMs,
                                                                    connectionTimeout, connectionTimeout);

            var maxConnectionCount = Math.Max(RedisConstants.MinConnectionCount, GetMaxConnectionCount());

            var limiterWait = (maxConnectionCount < 2) ? 0 : retryInfo.SpinStepTimeoutMs;

            while (retryInfo.RemainingTime > 0)
            {
                var signaled = m_ConnectionLimiter.Wait(limiterWait);
                if (signaled)
                {
                    try
                    {
                        return(NewConnection(DequeueSocket(dbIndex, expectedRole), dbIndex, expectedRole, true));
                    }
                    catch (Exception e)
                    {
                        m_ConnectionLimiter.Release();
                        if (e.IsSocketError())
                        {
                            throw;
                        }
                    }
                }

                retryInfo.Entered();
                OnConnectionRetry(retryInfo);

                if (!retryInfo.ContinueToSpin ||
                    retryInfo.CurrentRetryCount >= retryInfo.RetryCountLimit)
                {
                    OnConnectionLimitExceed(retryInfo);
                    if (retryInfo.ThrowError)
                    {
                        throw new RedisFatalException("Wait retry count exited the given maximum limit", RedisErrorCode.ConnectionError);
                    }
                    return(null);
                }
            }

            OnConnectionTimeout(retryInfo);
            if (retryInfo.ThrowError)
            {
                throw new RedisFatalException("Connection timeout occured while trying to connect", RedisErrorCode.ConnectionError);
            }
            return(null);
        }
Esempio n. 4
0
 protected virtual void OnConnectionLimitExceed(RedisConnectionRetryEventArgs e)
 {
 }