Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling empty response TryReadStringArrayWithLengthHeader #1009

Merged
merged 13 commits into from
Feb 14, 2025
2 changes: 1 addition & 1 deletion libs/client/GarnetClientProcessReplies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ unsafe bool ProcessReplyAsString(ref byte* ptr, byte* end, out string result, ou
if (!RespReadResponseUtils.TryReadStringArrayWithLengthHeader(out var resultArray, ref ptr, end))
return false;
// Return first element of array
if (resultArray != null) result = resultArray[0];
if (resultArray != null && resultArray.Length > 0) result = resultArray[0];
break;

default:
Expand Down
16 changes: 16 additions & 0 deletions test/Garnet.test/GarnetClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,22 @@ public async Task CanUseSetNxStringResultAsync()
ClassicAssert.AreEqual("Hello", resultMykey);
}

[Test]
public async Task ShouldNotThrowExceptionForEmptyArrayResponseAsync()
{
using var server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir);
server.Start();

using var db = TestUtils.GetGarnetClient();
await db.ConnectAsync();

ClassicAssert.DoesNotThrowAsync(async () =>
{
var result = await db.ExecuteForStringResultAsync("KEYS", ["*"]);
ClassicAssert.IsNull(result);
});
}

[Test]
public async Task CanUseMGetTests([Values] bool disableObjectStore)
{
Expand Down