예제 #1
0
        protected override RedisResult Expect(RedisAsyncRequest request)
        {
            SetWaitingCommit();

            var result = CreateEmptyResult(request.Expectation);

            m_Requests.Add(new RedisBatchRequest(request, result));

            return(result);
        }
예제 #2
0
        protected void Process(RedisAsyncRequest request)
        {
            if (request.Expectation == RedisCommandExpect.Void)
            {
                var command = request.Command;
                if (command.CommandType != RedisCommandType.SendNotReceive)
                {
                    command.CommandType = RedisCommandType.SendNotReceive;
                }

                m_AsyncClient.Expect(command);
                request.Response = new RedisVoid(0);
                return;
            }

            request.Response = ToExpectation(m_AsyncClient.Expect(request.Command),
                                             request.Expectation, request.ExpectedResult);
        }
예제 #3
0
 protected virtual RedisResult Expect(RedisAsyncRequest request)
 {
     Process(request);
     return(request.Response);
 }
예제 #4
0
        protected override void OnFlush(IList <RedisBatchRequest> batchRequests, out bool success)
        {
            success = false;

            var watches = Interlocked.Exchange(ref m_WatchQ, null);

            if (watches != null && watches.Count > 0)
            {
                var watch = new RedisAsyncRequest(
                    new RedisCommand(DbIndex, RedisCommandList.Watch,
                                     RedisCommandType.SendAndReceive, watches.ToArray()), RedisCommandExpect.OK);

                Process(watch);
            }

            Process(batchRequests);
            try
            {
                var exec = new RedisAsyncRequest(new RedisCommand(DbIndex, RedisCommandList.Exec), RedisCommandExpect.Array);
                Process(exec);

                success = true;

                var response = (RedisArray)exec.Response;
                if (response == null)
                {
                    Discard(batchRequests);
                }
                else
                {
                    var items = response.Value;
                    if (items == null || response.Length <= 0)
                    {
                        Discard(batchRequests);
                    }
                    else
                    {
                        var requestCount = batchRequests.Count;

                        var count = Math.Min(requestCount, items.Count);
                        for (var i = 0; i < count; i++)
                        {
                            var batch       = batchRequests[i];
                            var batchResult = batch.Result;

                            if (!ReferenceEquals(batchResult, null))
                            {
                                try
                                {
                                    var request     = batch.Request;
                                    var expectation = ToExpectation(items[i], request.Expectation, request.ExpectedResult);

                                    batchResult.TrySetResult(expectation.RawData);
                                }
                                catch (Exception e)
                                {
                                    batchResult.TrySetException(e);
                                }
                            }
                        }

                        if (count < requestCount)
                        {
                            for (var i = count; i < requestCount; i++)
                            {
                                var result = batchRequests[i].Result;
                                if (!ReferenceEquals(result, null))
                                {
                                    result.TryCancel();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Discard(batchRequests, e);
                throw;
            }
        }
예제 #5
0
 public RedisBatchRequest(RedisAsyncRequest request, RedisResult result)
 {
     Result  = result;
     Request = request;
 }