Skip to content

Commit 0a024c5

Browse files
committed
sync write; new _\r\n failing test
1 parent ca2700d commit 0a024c5

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using RESPite.Messages;
2+
using Xunit;
3+
4+
namespace RESPite.Tests;
5+
6+
public class RespScannerTests
7+
{
8+
[Fact]
9+
public void ScanNull()
10+
{
11+
RespScanState scanner = default;
12+
Assert.True(scanner.TryRead("_\r\n"u8, out var consumed));
13+
14+
Assert.Equal(3, consumed);
15+
Assert.Equal(3, scanner.TotalBytes);
16+
Assert.Equal(RespPrefix.Null, scanner.Prefix);
17+
}
18+
}

toys/StackExchange.Redis.Server/RedisServer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ protected virtual TypedRedisValue ClientReply(RedisClient client, in RedisReques
433433
protected virtual TypedRedisValue ClientId(RedisClient client, in RedisRequest request)
434434
=> TypedRedisValue.Integer(client.Id);
435435

436+
[RedisCommand(4, nameof(RedisCommand.CLIENT), "setinfo", LockFree = true)]
437+
protected virtual TypedRedisValue ClientSetInfo(RedisClient client, in RedisRequest request)
438+
=> TypedRedisValue.OK; // only exists to keep logs clean
439+
436440
private bool IsClusterEnabled(out TypedRedisValue fault)
437441
{
438442
if (ServerType == ServerType.Cluster)

toys/StackExchange.Redis.Server/RespServer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public async Task RunClientAsync(IDuplexPipe pipe, RedisServer.Node node = null,
285285
{
286286
node ??= DefaultNode;
287287
client = AddClient(node, state);
288+
288289
while (!client.Closed)
289290
{
290291
var readResult = await pipe.Input.ReadAsync().ConfigureAwait(false);
@@ -298,7 +299,8 @@ public async Task RunClientAsync(IDuplexPipe pipe, RedisServer.Node node = null,
298299
var response = Execute(client, request);
299300
client.ResetAfterRequest();
300301

301-
await WriteResponseAsync(client, pipe.Output, response, client.Protocol);
302+
WriteResponse(client, pipe.Output, response, client.Protocol);
303+
await pipe.Output.FlushAsync().ConfigureAwait(false);
302304

303305
// advance the buffer to account for the message we just read
304306
buffer = buffer.Slice(consumed);
@@ -344,7 +346,7 @@ public virtual void Log(string message)
344346
}
345347
}
346348

347-
public static async ValueTask WriteResponseAsync(RedisClient client, PipeWriter output, TypedRedisValue value, RedisProtocol protocol)
349+
public static void WriteResponse(RedisClient client, IBufferWriter<byte> output, TypedRedisValue value, RedisProtocol protocol)
348350
{
349351
static void WritePrefix(IBufferWriter<byte> output, char prefix)
350352
{
@@ -421,7 +423,7 @@ static void WritePrefix(IBufferWriter<byte> output, char prefix)
421423
throw new InvalidOperationException("Array element cannot be nil, index " + i);
422424

423425
// note: don't pass client down; this would impact SkipReplies
424-
await WriteResponseAsync(null, output, item, protocol);
426+
WriteResponse(null, output, item, protocol);
425427
}
426428
break;
427429
default:
@@ -438,8 +440,6 @@ static void WritePrefix(IBufferWriter<byte> output, char prefix)
438440
}
439441
}
440442

441-
await output.FlushAsync().ConfigureAwait(false);
442-
443443
static RespPrefix ToResp2(RespPrefix type)
444444
{
445445
switch (type)

0 commit comments

Comments
 (0)