Skip to content

Fix SPOP with count returning nil instead of an empty set for a missing key - #2096

Merged
kevin-montrose merged 3 commits into
microsoft:mainfrom
nileshpatil6:fix/spop-count-missing-key
Sep 11, 2026
Merged

kevin-montrose merged 3 commits into
microsoft:mainfrom
nileshpatil6:fix/spop-count-missing-key

Conversation

@nileshpatil6

Copy link
Copy Markdown
Contributor

Summary

SPOP has two reply shapes for a missing key in Redis: the no-count form replies nil, but the count form replies with an empty set (RESP2 *0, RESP3 ~0; spopWithCountCommand passes shared.emptyset to lookupKeyWriteOrReply).

Garnet's SetPop handler replies nil for both forms. Any client that drains a set with SPOP key <count> gets nil once the key disappears, where Redis hands back an empty collection. Typed clients that map the count form to a collection turn that into a null where application code expects an empty result.

Change

SRANDMEMBER in the same file already makes exactly this distinction on its NOTFOUND branch; this change gives SPOP the same treatment, using the existing protocol-aware WriteEmptySet helper so RESP3 gets the empty set type that the non-empty SPOP reply already uses. The SPOP key 0 early return is switched to the same helper (RESP2 output for it is unchanged).

Added a test for the count-with-missing-key reply next to the existing no-count missing-key test, which keeps passing unchanged, showing the nil reply for the no-count form is untouched.

Verification

New test fails on main with $-1\r\n where *0\r\n is expected, passes with the change. Full RespSetTest fixture: 86/86 pass (net10.0).

Copilot AI balanced review requested due to automatic review settings August 31, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The protocol-dependent RESP3 behavior and changed zero-count path need regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread test/standalone/Garnet.test.collections/RespSetTest.cs
@kevin-montrose
kevin-montrose merged commit a01b75f into microsoft:main Sep 11, 2026
169 checks passed
x@01 (x-at-01) added a commit to webc-fork/garnet that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants