protected override RedisResult Expect(RedisAsyncRequest request) { SetWaitingCommit(); var result = CreateEmptyResult(request.Expectation); m_Requests.Add(new RedisBatchRequest(request, result)); return(result); }
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); }
protected virtual RedisResult Expect(RedisAsyncRequest request) { Process(request); return(request.Response); }
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; } }
public RedisBatchRequest(RedisAsyncRequest request, RedisResult result) { Result = result; Request = request; }