From 8c0c029ac9a5d7d2f1885b9d8635a7857057e672 Mon Sep 17 00:00:00 2001 From: nileshpatil6 Date: Mon, 31 Aug 2026 23:16:22 +0530 Subject: [PATCH] Fix SPOP with count returning nil instead of an empty set for a missing key --- libs/server/Resp/Objects/SetCommands.cs | 10 ++++++++-- test/standalone/Garnet.test.collections/RespSetTest.cs | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/server/Resp/Objects/SetCommands.cs b/libs/server/Resp/Objects/SetCommands.cs index 21167b9ebcc..30e07867a5b 100644 --- a/libs/server/Resp/Objects/SetCommands.cs +++ b/libs/server/Resp/Objects/SetCommands.cs @@ -535,8 +535,7 @@ private unsafe bool SetPop(ref TGarnetApi storageApi) if (countParameter == 0) { - while (!RespWriteUtils.TryWriteEmptyArray(ref dcurr, dend)) - SendAndReset(); + WriteEmptySet(); return true; } @@ -558,6 +557,13 @@ private unsafe bool SetPop(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: diff --git a/test/standalone/Garnet.test.collections/RespSetTest.cs b/test/standalone/Garnet.test.collections/RespSetTest.cs index b0be3d5ecc8..9713d8f7c5a 100644 --- a/test/standalone/Garnet.test.collections/RespSetTest.cs +++ b/test/standalone/Garnet.test.collections/RespSetTest.cs @@ -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() {