private RedisSubscription(RedisConnectionSettings connectionSettings, Encoding encoding) { _connection = new RedisConnection(connectionSettings); _writer = new RespWriter(_connection.GetStream()); _reader = new RespReader(_connection.GetStream()); _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); }
public async Task Should_read_normal_messages(string name, string rawMessage, RespMessage message) { var stream = new MemoryStream(Encoding.GetBytes(rawMessage)); var reader = new RespReader(stream); var actual = await reader.ReadAsync(); Assert.That(actual, Is.EqualTo(message)); }
public async Task <T> ExecuteAsync() { using (var writer = new RespWriter(_stream)) { await WriteStartCommandAsync(writer); await WriteParametersAsync(writer); await WriteEndCommandAsync(writer); } using var reader = new RespReader(_stream); return(ReadResult(reader).Result); }
public T Execute() { using (var writer = new RespWriter(_stream)) { WriteStartCommand(writer); WriteParameters(writer); WriteEndCommand(writer); } using var reader = new RespReader(_stream); return(ReadResult(reader).Result); }
private static long ReadIntegerValue(RespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); throw new RedisErrorException(err); } if (dataType != RespDataType.Integer) { throw new InvalidDataException(); } return(reader.ReadIntegerValue()); }
private static byte[] ReadBulkStringValue(RespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); throw new RedisErrorException(err); } if (dataType != RespDataType.BulkString) { throw new InvalidDataException(); } return(reader.ReadBulkStringValue()); }
private static IList <byte[]> ReadArrayOfBulkStrings(RespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); throw new RedisErrorException(err); } if (dataType != RespDataType.Array) { throw new InvalidDataException(); } if (!reader.TryReadStartArray(out long length)) { return(null); } var values = new List <byte[]>(); for (var i = 0; i < length; i++) { dataType = reader.ReadDataType(); if (dataType != RespDataType.BulkString) { throw new InvalidDataException(); } byte[] value = reader.ReadBulkStringValue(); values.Add(value); } return(values); }