internal RedisData ReadComplexResponse() { int c = SafeReadByte(); if (c == -1) { throw CreateNoMoreDataError(); } var s = ReadLine(); if (log.IsDebugEnabled) { Log("R: {0}", s); } switch (c) { case '$': return(new RedisData { Data = ParseSingleLine(string.Concat(char.ToString((char)c), s)) }); case '-': throw CreateResponseError(s.StartsWith("ERR") ? s.Substring(4) : s); case '*': int count; if (int.TryParse(s, out count)) { var ret = new RedisData { Children = new List <RedisData>() }; for (var i = 0; i < count; i++) { ret.Children.Add(ReadComplexResponse()); } return(ret); } break; default: return(new RedisData { Data = s.ToUtf8Bytes() }); } throw CreateResponseError("Unknown reply on multi-request: " + c + s); }
private async ValueTask <RedisData> ReadComplexResponseAsync(CancellationToken token) { int c = await SafeReadByteAsync(token).ConfigureAwait(false); if (c == -1) { throw CreateNoMoreDataError(); } var s = await ReadLineAsync(token).ConfigureAwait(false); if (log.IsDebugEnabled) { Log("R: {0}", s); } switch (c) { case '$': return(new RedisData { Data = await ParseSingleLineAsync(string.Concat(char.ToString((char)c), s), token).ConfigureAwait(false) }); case '-': throw CreateResponseError(s.StartsWith("ERR") ? s.Substring(4) : s); case '*': if (int.TryParse(s, out var count)) { var ret = new RedisData { Children = new List <RedisData>() }; for (var i = 0; i < count; i++) { ret.Children.Add(await ReadComplexResponseAsync(token).ConfigureAwait(false)); } return(ret); } break; default: return(new RedisData { Data = s.ToUtf8Bytes() }); } throw CreateResponseError("Unknown reply on multi-request: " + ((char)c) + s); // c here is the protocol prefix }
public static RedisText ToRedisText(this RedisData data) { var to = new RedisText(); if (data.Data != null) { to.Text = data.Data.FromUtf8Bytes(); } if (data.Children != null) { to.Children = data.Children.ConvertAll(x => x.ToRedisText()); } return(to); }
internal RedisData ReadComplexResponse() { int c = SafeReadByte(); if (c == -1) throw CreateResponseError("No more data"); var s = ReadLine(); if (log.IsDebugEnabled) Log("R: {0}", s); switch (c) { case '$': return new RedisData { Data = ParseSingleLine(string.Concat(char.ToString((char) c), s)) }; case '-': throw CreateResponseError(s.StartsWith("ERR") ? s.Substring(4) : s); case '*': int count; if (int.TryParse(s, out count)) { var ret = new RedisData { Children = new List<RedisData>() }; for (var i = 0; i < count; i++) { ret.Children.Add(ReadComplexResponse()); } return ret; } break; default: return new RedisData { Data = s.ToUtf8Bytes() }; } throw CreateResponseError("Unknown reply on multi-request: " + c + s); }
public static long ToInt64(this RedisData data) => long.Parse(data.Data.FromUtf8Bytes(), NumberStyles.Integer, CultureInfo.InvariantCulture);
public static double ToDouble(this RedisData data) => double.Parse(data.Data.FromUtf8Bytes(), NumberStyles.Float, CultureInfo.InvariantCulture);