// internally, this is very similar to RawResult, except it is designed to be usable // outside of the IO-processing pipeline: the buffers are standalone, etc internal static RedisResult TryCreate(PhysicalConnection connection, RawResult result) { try { switch (result.Type) { case ResultType.Integer: case ResultType.SimpleString: case ResultType.BulkString: return new SingleRedisResult(result.AsRedisValue()); case ResultType.MultiBulk: var items = result.GetItems(); var arr = new RedisResult[items.Length]; for (int i = 0; i < arr.Length; i++) { var next = TryCreate(connection, items[i]); if (next == null) return null; // means we didn't understand arr[i] = next; } return new ArrayRedisResult(arr); case ResultType.Error: return new ErrorRedisResult(result.GetString()); default: return null; } } catch(Exception ex) { connection?.OnInternalError(ex); return null; // will be logged as a protocol fail by the processor } }
internal override bool TryValidate(RawResult result, out bool value) { switch (result.Type) { case ResultType.BulkString: case ResultType.SimpleString: case ResultType.Integer: var parsed = result.AsRedisValue(); if (expectedValue.HasValue) { value = (parsed == expectedValue.Value) == expectedResult; ConnectionMultiplexer.TraceWithoutContext("actual: " + (string)parsed + "; expected: " + (string)expectedValue.Value + "; wanted: " + (expectedResult ? "==" : "!=") + "; voting: " + value); } else { value = (parsed.IsNull != expectedResult); ConnectionMultiplexer.TraceWithoutContext("exists: " + parsed + "; expected: " + expectedResult + "; voting: " + value); } return(true); } value = false; return(false); }
protected override HashEntry Parse(RawResult first, RawResult second) { return(new HashEntry(first.AsRedisValue(), second.AsRedisValue())); }
protected override SortedSetEntry Parse(RawResult first, RawResult second) { double val; return(new SortedSetEntry(first.AsRedisValue(), second.TryGetDouble(out val) ? val : double.NaN)); }