Skip to content

feat: add putIfAbsent/replace/containsKey conditional operations - #5

Merged
rigazilla merged 1 commit into
mainfrom
feature/conditional-operations
Sep 18, 2026
Merged

rigazilla merged 1 commit into
mainfrom
feature/conditional-operations

Conversation

@rigazilla

Copy link
Copy Markdown
Member

Summary

Completes Step 10 with the three remaining conditional operations:

Operation Opcodes Returns
putIfAbsent 0x05 / 0x06 future<optional<EntryWithMetadata>>
replace (only if present) 0x07 / 0x08 future<optional<EntryWithMetadata>>
containsKey 0x0F / 0x10 future<bool>
  • putIfAbsent / replace reuse PUT's request layout (key + expiration byte + value). They return the previous / replaced entry when previousValue (FORCE_RETURN_VALUE) is set, nullopt otherwise; parsers drain the *_WITH_PREVIOUS (0x03/0x04) body defensively so the shared read loop stays byte-aligned once that flag is wired up.
  • containsKey is a key-only request returning a bool from the response status (no response body).

Cross-check

Verified against all three legs:

  • This client — request encoders mirror the existing put() / get().
  • Java — PutIfAbsentOperation, ReplaceOperation, ContainsKeyOperation (all extend the same key/value/key operation bases).
  • hotrod40.ksy — put_if_absent / replace dispatch to put_request / put_response; contains_key dispatches to key_request with a status-only response.

Tests

  • 11 unit tests (PutIfAbsentTest, ReplaceTest, ContainsKeyTest) — request encoding + opcode constants.
  • 12 integration tests (PutIfAbsent, Replace, ContainsKey) — stored/not-stored/previous-value semantics against Docker Infinispan.
  • Unit 176/176, integration 75/75 across 14 suites. Clean Release build with -Werror -Wall -Wextra.

🤖 Generated with Claude Code

Completes Step 10 with the three remaining conditional operations:

- putIfAbsent (0x05/0x06): store only if the key is absent
- replace (0x07/0x08): store only if the key is present
- containsKey (0x0F/0x10): key-existence test

putIfAbsent/replace reuse PUT's request layout (key + expiration byte +
value) and return future<optional<EntryWithMetadata>> — the previous /
replaced entry when previousValue (FORCE_RETURN_VALUE) is set, nullopt
otherwise. Parsers drain the *_WITH_PREVIOUS (0x03/0x04) body defensively.
containsKey is a key-only request returning future<bool> from the status
(no response body).

Cross-checked against Java PutIfAbsentOperation / ReplaceOperation /
ContainsKeyOperation and hotrod40.ksy (put_if_absent/replace map to
put_request/put_response; contains_key maps to key_request with a
status-only response).

Tests: 11 unit + 12 integration, all passing. Unit 176/176, integration
75/75 across 14 suites. Clean Release build with -Werror -Wall -Wextra.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rigazilla
rigazilla merged commit 93d066f into main Sep 18, 2026
3 checks passed
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.

1 participant