Ejemplo n.º 1
0
        public bool Enqueue(RedisAsyncRequest request)
        {
            if (request != null)
            {
                ValidateNotDisposed();

                EnqueueInternal(request);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public RedisAsyncRequest <T> Enqueue <T>(RedisCommand command, RedisCommandExpect expect, string okIf)
        {
            if (command != null)
            {
                ValidateNotDisposed();

                var member = new RedisAsyncRequest <T>(command, expect, okIf,
                                                       new TaskCompletionSource <T>(command));

                EnqueueInternal(member);
                return(member);
            }
            return(null);
        }
Ejemplo n.º 3
0
 private void CancelRequest(RedisAsyncRequest member)
 {
     if (member != null)
     {
         try
         {
             member.Cancel();
         }
         finally
         {
             member.Dispose();
         }
     }
 }
Ejemplo n.º 4
0
 private void EnqueueInternal(RedisAsyncRequest request)
 {
     lock (m_AsyncMessageQLock)
     {
         var prevTail = Interlocked.Exchange(ref m_QTail, request);
         if (prevTail != null)
         {
             var store = m_AsyncRequestQ;
             if (store != null)
             {
                 store.AddLast(prevTail);
             }
         }
         m_Count++;
     }
 }
        protected override void DoProcessRequest(RedisAsyncRequest request, RedisSocketContext context)
        {
            var cancelRequest = true;

            try
            {
                if (Disposed)
                {
                    return;
                }

                if (request.Send(context))
                {
                    if (Disposed)
                    {
                        return;
                    }

                    Interlocked.Exchange(ref m_CurrentContext, context);

                    var receiveQ = m_ReceiveQ;
                    if (receiveQ != null)
                    {
                        receiveQ.Enqueue(request);
                        cancelRequest = false;

                        m_ReceiveGate.Set();
                    }
                }
            }
            catch (Exception)
            { }
            finally
            {
                if (cancelRequest)
                {
                    request.Cancel();
                }
            }
        }
 protected virtual void DoProcessRequest(RedisAsyncRequest request, RedisSocketContext context)
 {
     request.Process(context);
 }
Ejemplo n.º 7
0
        public bool TryDequeueOneOf(int dbIndex1, int dbIndex2, out RedisAsyncRequest result)
        {
            result = null;
            var member = (RedisAsyncRequest)null;

            lock (m_AsyncMessageQLock)
            {
                if (m_Count == 0)
                {
                    return(false);
                }

                member  = m_QTail;
                m_QTail = null;
            }

            if (member != null)
            {
                try
                {
                    var command = member.Command;
                    if ((dbIndex1 < 0 || command.DbIndex == dbIndex1) ||
                        (dbIndex2 < 0 || command.DbIndex == dbIndex2))
                    {
                        m_Count--;
                        result = member;
                        return(true);
                    }
                }
                catch (Exception)
                { }
            }

            if (m_AsyncRequestQ != null)
            {
                lock (m_AsyncMessageQLock)
                {
                    var store = m_AsyncRequestQ;
                    if (store != null)
                    {
                        var node = store.First;
                        while (node != null)
                        {
                            try
                            {
                                member = node.Value;
                                if (member != null)
                                {
                                    try
                                    {
                                        var command = member.Command;
                                        if ((dbIndex1 < 0 || command.DbIndex == dbIndex1) ||
                                            (dbIndex2 < 0 || command.DbIndex == dbIndex2))
                                        {
                                            store.Remove(node);
                                            m_Count--;

                                            result = member;
                                            return(true);
                                        }
                                    }
                                    catch (Exception)
                                    { }
                                }
                            }
                            catch (Exception)
                            { }

                            node = node.Next;
                        }
                    }
                }
            }
            return(false);
        }