Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libs/server/Resp/Objects/SetCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ private unsafe bool SetPop<TGarnetApi>(ref TGarnetApi storageApi)

if (countParameter == 0)
{
while (!RespWriteUtils.TryWriteEmptyArray(ref dcurr, dend))
SendAndReset();
WriteEmptySet();

return true;
}
Expand All @@ -558,6 +557,13 @@ private unsafe bool SetPop<TGarnetApi>(ref TGarnetApi storageApi)
ProcessOutput(output.SpanByteAndMemory);
break;
case GarnetStatus.NOTFOUND:
if (parseState.Count == 2)
{
// SPOP key count replies with an empty set when the key does not exist
WriteEmptySet();
break;
}

WriteNull();
break;
case GarnetStatus.WRONGTYPE:
Expand Down
9 changes: 9 additions & 0 deletions test/standalone/Garnet.test.collections/RespSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,15 @@ public void CanDoSPOPCommandWhenKeyDoesNotExistLC()
TestUtils.AssertEqualUpToExpectedLength(expectedResponse, response);
}

[Test]
public void CanDoSPOPWithCountCommandWhenKeyDoesNotExistLC()
{
using var lightClientRequest = TestUtils.CreateRequest();
var response = lightClientRequest.SendCommand("SPOP fooset 3");
var expectedResponse = "*0\r\n";
TestUtils.AssertEqualUpToExpectedLength(expectedResponse, response);
}

[Test]
public void CanUseNotExistingSetwithSMembers()
{
Expand Down
Loading