public RedisBatchRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null, RedisRequestType requestType = RedisRequestType.Batch) : base(command, expectation, okIf, requestType) { if (requestType - RedisConstants.RedisBatchBase < 0) { throw new RedisException("Request type must be one of batch types", RedisErrorCode.InvalidParameter); } }
protected internal override T Expect <T>(RedisCommand command, RedisCommandExpect expectation, string okIf = null) { switch (expectation) { case RedisCommandExpect.Response: return((T)(object)Pool.Execute(command, ThrowOnError)); case RedisCommandExpect.Array: return((T)(object)Pool.ExpectArray(command, ThrowOnError)); case RedisCommandExpect.BulkString: return((T)(object)Pool.ExpectBulkString(command, ThrowOnError)); case RedisCommandExpect.BulkStringBytes: return((T)(object)Pool.ExpectBulkStringBytes(command, ThrowOnError)); case RedisCommandExpect.Double: return((T)(object)Pool.ExpectDouble(command, ThrowOnError)); case RedisCommandExpect.GreaterThanZero: return((T)(object)Pool.ExpectInteger(command, ThrowOnError)); case RedisCommandExpect.Integer: return((T)(object)Pool.ExpectInteger(command, ThrowOnError)); case RedisCommandExpect.MultiDataBytes: return((T)(object)Pool.ExpectMultiDataBytes(command, ThrowOnError)); case RedisCommandExpect.MultiDataStrings: return((T)(object)Pool.ExpectMultiDataStrings(command, ThrowOnError)); case RedisCommandExpect.Nothing: return((T)(object)Pool.ExpectNothing(command, ThrowOnError)); case RedisCommandExpect.NullableDouble: return((T)(object)Pool.ExpectNullableDouble(command, ThrowOnError)); case RedisCommandExpect.NullableInteger: return((T)(object)Pool.ExpectNullableInteger(command, ThrowOnError)); case RedisCommandExpect.OK: return((T)(object)Pool.ExpectOK(command, ThrowOnError)); case RedisCommandExpect.One: return((T)(object)Pool.ExpectOne(command, ThrowOnError)); case RedisCommandExpect.SimpleString: return((T)(object)Pool.ExpectSimpleString(command, ThrowOnError)); case RedisCommandExpect.SimpleStringBytes: return((T)(object)Pool.ExpectSimpleStringBytes(command, ThrowOnError)); default: throw new RedisException(String.Format("Undefined expectation type, {0}", expectation.ToString("F")), RedisErrorCode.NotSupported); } }
protected RedisRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null, object stateObject = null, RedisRequestType requestType = RedisRequestType.Default) { m_OKIf = okIf; m_Expectation = expectation; m_Command = command; m_StateObject = stateObject; m_RequestType = requestType; m_CreationTime = DateTime.UtcNow; }
private AsyncExecuteResult <T> TryToExecuteAsync <T>(RedisCommand command, RedisCommandExpect expect, string okIf) { if (command == null) { throw new RedisFatalException(new ArgumentNullException("command")); } ValidateNotDisposed(); return(TryToExecuteAsyncInternal <T>(command, expect, okIf)); }
public Task <T> Enqueue <T>(RedisCommand command, RedisCommandExpect expect, string okIf) { var asycRequestQ = m_AsycRequestQ; if (asycRequestQ != null) { var asyncRequest = asycRequestQ.Enqueue <T>(command, expect, okIf); Start(); return(asyncRequest.Task); } return(null); }
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); }
protected internal override T Expect <T>(RedisCommand command, RedisCommandExpect expectation, string okIf = null) { SetWaitingCommit(); var requests = m_RequestQ; if (requests == null) { requests = (m_RequestQ = new List <RedisRequest>()); } var request = CreateRequest <T>(command, expectation, okIf); requests.Add(request); var result = request.Result; return(!ReferenceEquals(result, null) ? (T)(object)result : default(T)); }
protected RedisResult CreateEmptyResult(RedisCommandExpect expect) { switch (expect) { case RedisCommandExpect.Array: return(new RedisArray()); case RedisCommandExpect.BulkString: case RedisCommandExpect.SimpleString: return(new RedisString()); case RedisCommandExpect.BulkStringBytes: return(new RedisBytes()); case RedisCommandExpect.OK: case RedisCommandExpect.GreaterThanZero: case RedisCommandExpect.One: return(new RedisBool()); case RedisCommandExpect.MultiDataBytes: return(new RedisMultiBytes()); case RedisCommandExpect.MultiDataStrings: return(new RedisMultiString()); case RedisCommandExpect.Integer: return(new RedisInteger()); case RedisCommandExpect.Double: return(new RedisDouble()); case RedisCommandExpect.NullableInteger: return(new RedisNullableInteger()); case RedisCommandExpect.NullableDouble: return(new RedisNullableDouble()); case RedisCommandExpect.Void: return(new RedisVoid()); } throw new RedisException("Unexpected type", RedisErrorCode.CorruptResponse); }
private AsyncExecuteResult <T> TryToExecuteAsyncInternal <T>(RedisCommand command, RedisCommandExpect expect, string okIf) { var result = new AsyncExecuteResult <T>(); if (m_UseAsyncCompleter) { var connection = !m_AsyncCompleterEnforced?Connect(command.DbIndex, command.Role) : null; if (connection != null) { result.Connection = connection; } else { var task = m_AsycRequestQProcessor.Enqueue <T>(command, expect, okIf); if (!ReferenceEquals(task, null)) { result.Result = task.Result; } result.Handled = true; } } return(result); }
protected virtual RedisBatchRequest <T> CreateRequest <T>(RedisCommand command, RedisCommandExpect expectation, string okIf) where T : RedisResult { return(new RedisBatchRequest <T>(command, expectation, okIf)); }
protected RedisRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null, RedisRequestType requestType = RedisRequestType.Default) : base(command, expectation, okIf, null, requestType) { }
public RedisPipelineRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null) : base(command, expectation, okIf, RedisRequestType.Pipelined) { }
public RedisAsyncRequest(RedisCommand command, RedisCommandExpect expectation, string expectedResult = null) { Command = command; Expectation = expectation; ExpectedResult = expectedResult; }
public RedisTransactionalRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null) : base(command, expectation, okIf, RedisRequestType.Transactional) { }
protected override RedisBatchRequest <T> CreateRequest <T>(RedisCommand command, RedisCommandExpect expectation, string okIf) { return(new RedisTransactionalRequest <T>(command, expectation, okIf)); }
protected internal virtual T Expect <T>(RedisCommand command, RedisCommandExpect expectation, string okIf = null) where T : RedisResult { throw new RedisException("Undefined exception", RedisErrorCode.NotSupported); }
protected RedisResult ToExpectation(RedisResult response, RedisCommandExpect expectation, string expectedResult = null) { switch (expectation) { case RedisCommandExpect.BulkStringBytes: { var result = response as RedisBytes; if (ReferenceEquals(result, null)) { throw new RedisException("Unexpected type", RedisErrorCode.CorruptResponse); } return(result); } case RedisCommandExpect.Array: { if (!(response is RedisArray)) { throw new RedisException("Unexpected type", RedisErrorCode.CorruptResponse); } return(response); } case RedisCommandExpect.BulkString: { var result = response as RedisBytes; if (ReferenceEquals(result, null)) { throw new RedisException("Unexpected type", RedisErrorCode.CorruptResponse); } var bytes = result.Value; if (bytes == null) { return(new RedisString(null)); } return(new RedisString(bytes.ToUTF8String())); } case RedisCommandExpect.OK: { var result = response as RedisString; if (ReferenceEquals(result, null)) { throw new RedisFatalException("Unexpected value returned"); } return(new RedisBool(result.Value == RedisConstants.OK)); } case RedisCommandExpect.SimpleString: { if (!(response is RedisString)) { throw new RedisFatalException("Unexpected value returned"); } return(response); } case RedisCommandExpect.SimpleStringResult: { var result = response as RedisString; if (ReferenceEquals(result, null)) { throw new RedisFatalException("Unexpected value returned"); } return(new RedisBool(result.Value == expectedResult)); } case RedisCommandExpect.Integer: { if (!(response is RedisInteger)) { throw new RedisException("Not an integer result", RedisErrorCode.CorruptResponse); } return(response); } case RedisCommandExpect.MultiDataBytes: { var array = response as RedisArray; if (ReferenceEquals(array, null)) { return(new RedisMultiBytes(null)); } return(new RedisMultiBytes(array.ToMultiBytes())); } case RedisCommandExpect.MultiDataStrings: { var array = response as RedisArray; if (ReferenceEquals(array, null)) { return(new RedisMultiString(null)); } return(new RedisMultiString(array.ToMultiString())); } case RedisCommandExpect.Double: { if (!ReferenceEquals(response, null)) { if (response is RedisInteger) { return(new RedisDouble(((RedisInteger)response).Value)); } if (response is RedisString) { var str = ((RedisString)response).Value; if (!String.IsNullOrEmpty(str)) { double d; if (double.TryParse(str, out d)) { return(new RedisDouble(d)); } } } else if (response is RedisBytes) { var bytes = ((RedisBytes)response).Value; if (bytes != null && bytes.Length > 0) { double d; if (double.TryParse(bytes.ToUTF8String(), out d)) { return(new RedisDouble(d)); } } } } throw new RedisException("Not a double result", RedisErrorCode.CorruptResponse); } case RedisCommandExpect.NullableInteger: { if (response is RedisInteger) { return(new RedisNullableInteger(((RedisInteger)response).Value)); } if (response is RedisString) { var str = ((RedisString)response).Value; if (String.IsNullOrEmpty(str)) { return(new RedisNullableInteger(null)); } if (str == RedisConstants.NilStr) { return(new RedisNullableInteger(null)); } long l; if (str.TryParse(out l)) { return(new RedisNullableInteger(l)); } } else if (response is RedisBytes) { var bytes = ((RedisBytes)response).Value; if (bytes == null || bytes.Length == 0) { return(new RedisNullableInteger(null)); } if (bytes.EqualTo(RedisConstants.Nil)) { return(new RedisNullableInteger(null)); } long l; if (bytes.TryParse(out l)) { return(new RedisNullableInteger(l)); } } throw new RedisException("Not an integer result", RedisErrorCode.CorruptResponse); } case RedisCommandExpect.NullableDouble: { if (ReferenceEquals(response, null)) { return(new RedisNullableDouble(null)); } if (response is RedisInteger) { return(new RedisNullableDouble(((RedisInteger)response).Value)); } if (response is RedisString) { var str = ((RedisString)response).Value; if (String.IsNullOrEmpty(str)) { return(new RedisNullableDouble(null)); } if (str == RedisConstants.NilStr) { return(new RedisNullableDouble(null)); } double d; if (double.TryParse(str, out d)) { return(new RedisNullableDouble(d)); } } else if (response is RedisBytes) { var bytes = ((RedisBytes)response).Value; if (bytes == null || bytes.Length == 0) { return(new RedisNullableDouble(null)); } if (bytes.EqualTo(RedisConstants.Nil)) { return(new RedisNullableDouble(null)); } double d; if (double.TryParse(bytes.ToUTF8String(), out d)) { return(new RedisNullableDouble(d)); } } throw new RedisException("Not a double result", RedisErrorCode.CorruptResponse); } case RedisCommandExpect.GreaterThanZero: { var result = response as RedisInteger; if (ReferenceEquals(result, null)) { throw new RedisException("Not an integer result", RedisErrorCode.CorruptResponse); } return(new RedisBool(result.Value > RedisConstants.Zero)); } case RedisCommandExpect.One: { var result = response as RedisInteger; if (ReferenceEquals(result, null)) { throw new RedisFatalException("Unexpected value returned"); } return(new RedisBool(result.Value == RedisConstants.One)); } case RedisCommandExpect.Void: return(new RedisVoid(0)); } throw new RedisException("Unexpected type", RedisErrorCode.CorruptResponse); }
public RedisAsyncRequest(RedisCommand command, RedisCommandExpect expectation, string okIf, TaskCompletionSource <T> completionSource) : base(command, expectation, okIf, completionSource) { }
protected RedisAsyncRequest(RedisCommand command, RedisCommandExpect expectation, string okIf = null, object stateObject = null) : base(command, expectation, okIf, stateObject, RedisRequestType.Async) { }