Skip to content

feat(string): support IFEQ/IFNE/IFDEQ/IFDNE in SET command (#3311)#3393

Open
kirito632 wants to merge 4 commits intoapache:unstablefrom
kirito632:feat/set-ifeq-ifne-ifdeq-ifdne
Open

feat(string): support IFEQ/IFNE/IFDEQ/IFDNE in SET command (#3311)#3393
kirito632 wants to merge 4 commits intoapache:unstablefrom
kirito632:feat/set-ifeq-ifne-ifdeq-ifdne

Conversation

@kirito632
Copy link

@kirito632 kirito632 commented Mar 18, 2026

What this PR does / why we need it

This PR implements the IFEQ, IFNE, IFDEQ, and IFDNE options for the
SET command, resolving #3311.

  • IFEQ <value>: only set if key exists and current value equals <value>
  • IFNE <value>: only set if key does not exist, or current value differs from <value>
  • IFDEQ <digest>: only set if key exists and digest of current value equals <digest>
  • IFDNE <digest>: only set if key does not exist, or digest of current value differs from <digest>

Which issue(s) this PR fixes

Closes #3311

Test coverage

  • Added 6 C++ unit tests covering all four options, plus GET and TTL combinations
  • Added Go integration tests in TestSetConditional covering syntax errors,
    basic behavior, GET/EX combinations, and 10 property-based tests

AI assistance

AI tools were used for the initial implementation draft and test scaffolding.
Logic was reviewed manually against the Redis 8.x documentation and kvrocks
coding conventions.

@PragmaTwice
Copy link
Member

When GET is combined with IFEQ/IFNE/IFDEQ/IFDNE and the condition is
not met, return the previous value (not nil), consistent with how
Redis handles GET+NX/XX and the official Redis 8.x documentation.
When GET is combined with a conditional SET (IFEQ/IFNE/IFDEQ/IFDNE),
the previous value is always returned regardless of whether the
condition was met. The Go test incorrectly expected nil when the
condition was not met; fix it to expect the old value.

Also replace non-ASCII arrow characters in C++ test comments with
plain ASCII equivalents to match kvrocks coding conventions.
@kirito632
Copy link
Author

Thanks for the pointer. I used AI tools to assist with the initial implementation draft and test scaffolding. I reviewed the logic myself against the Redis 8.x documentation, caught and fixed a wrong test assertion (GET+IFEQ condition-not-met should return the old value, not nil), and cleaned up non-ASCII comments to match kvrocks conventions. I understand the implementation and can explain any part of it.

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.

Add support of IFEQ/IFNE/IFDEQ/IFDNE in SET command

2 participants