예제 #1
0
        internal bool AssertConnectedSocket()
        {
            try
            {
                TryConnectIfNeeded();
                var isConnected = socket != null;
                return(isConnected);
            }
            catch (SocketException ex)
            {
                log.Error(ErrorConnect.Fmt(Host, Port));

                if (socket != null)
                {
                    socket.Close();
                }

                socket = null;

                DeactivatedAt = DateTime.UtcNow;
                var message = "" + Host + ":" + Port;
                var throwEx = new RedisException(message, ex);
                log.Error(throwEx.Message, ex);
                throw throwEx;
            }
        }
예제 #2
0
        private RedisException CreateConnectionError()
        {
            DeactivatedAt = DateTime.UtcNow;
            var throwEx = new RedisException(
                string.Format("Unable to Connect: sPort: {0}",
                              clientPort), lastSocketException);

            log.Error(throwEx.Message);
            throw throwEx;
        }
예제 #3
0
        private RedisSentinelWorker GetValidSentinelWorker()
        {
            if (isDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (this.worker != null)
            {
                return(this.worker);
            }

            RedisException lastEx = null;

            while (this.worker == null && ShouldRetry())
            {
                try
                {
                    this.worker = GetNextSentinel();
                    GetRedisManager();
                    this.worker.BeginListeningForConfigurationChanges();
                    this.failures = 0; //reset
                    return(this.worker);
                }
                catch (RedisException ex)
                {
                    if (OnWorkerError != null)
                    {
                        OnWorkerError(ex);
                    }

                    lastEx = ex;
                    this.failures++;
                    Interlocked.Increment(ref RedisState.TotalFailedSentinelWorkers);
                }
            }

            this.failures = 0; //reset
            Thread.Sleep(WaitBetweenFailedHosts);

            throw new RedisException("No Redis Sentinels were available", lastEx);
        }