Beispiel #1
0
        protected override void OnDispose(bool disposing)
        {
            base.OnDispose(disposing);

            RedisConnectionStats.DecrInUseConnections();

            Interlocked.Exchange(ref m_Settings, null);
            Interlocked.Exchange(ref m_CreateAction, null);

            var onReleaseSocket = Interlocked.Exchange(ref m_ReleaseAction, null);

            if (onReleaseSocket != null)
            {
                var socket = Interlocked.Exchange(ref m_Socket, null);
                try
                {
                    if (onReleaseSocket != null)
                    {
                        onReleaseSocket(this, socket);
                    }
                }
                catch (Exception e)
                {
                    if (e.IsSocketError())
                    {
                        socket.DisposeSocket();
                    }
                }
            }
        }
Beispiel #2
0
        internal RedisConnection(string name,
                                 RedisRole expectedRole, RedisConnectionSettings settings,
                                 Action <RedisConnection, RedisSocket> onCreateSocket,
                                 Action <RedisConnection, RedisSocket> onReleaseSocket,
                                 RedisSocket socket = null, bool connectImmediately = false)
        {
            if (settings == null)
            {
                throw new RedisFatalException(new ArgumentNullException("settings"));
            }

            if (onReleaseSocket == null)
            {
                throw new RedisFatalException(new ArgumentNullException("onReleaseSocket"));
            }

            RedisConnectionStats.IncrInUseConnections();

            m_ExpectedRole  = expectedRole;
            m_Settings      = settings ?? RedisConnectionSettings.Default;
            m_CreateAction  = onCreateSocket;
            m_ReleaseAction = onReleaseSocket;
            m_Name          = !name.IsEmpty() ? name : (GetType().Name + ", " + m_Id.ToString());

            if ((socket != null) && socket.Connected)
            {
                m_Socket = socket;
                m_State  = (int)RedisConnectionState.Connected;
            }

            try
            {
                if (connectImmediately)
                {
                    ConnectInternal();
                }
            }
            catch (Exception)
            { }
        }