feat: implement HSETEX command (#299) - #334
Merged
Merged
Conversation
Adds the Redis 8.0 HSETEX command for setting one or more hash fields with optional FNX/FXX existence conditions and EX/PX/EXAT/PXAT/KEEPTTL expiration handling, gated to redis-8.0+/valkey-9.0+. Part of the redis-8.0 compatibility delta tracked by #299 (a large umbrella issue covering unrelated Redis Stack module families that are out of scope for this change).
ctx.db.getHash() returns the raw hash shape (no .hasField()); the previous FNX/FXX check reimplemented field-expiry logic against it instead of reusing TrackedHashData, which already handles this and is available inside ctx.db.updateHash(). Checking the condition inside that same callback also means a failed condition on a missing key never persists an empty hash, without a separate getHash() pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HSETEX key [FNX|FXX] [EX seconds|PX ms|EXAT unix-s|PXAT unix-ms|KEEPTTL] FIELDS numfields field value [field value ...], gatedredis-8.0+/valkey-9.0+.FNX/FXXrequire all-or-nothing field existence; the condition/expiration tokens may appear in either order; overwriting a field without an expiration clause clears its TTL (like plainHSET),KEEPTTLretains it, andEX 0/pastEXAT/PXATdelete the field immediately; deleting the last field removes the key.unknown argument: X,Only one of FXX or FNX...,Only one of EX, PX, EXAT, PXAT or KEEPTTL...,invalid number of fields, generic wrong-arity for numfields/pair-count mismatches) were verified against a liveredis:8.0container — several diverge fromHGETEX's wording, which is intentional (matches real Redis, not just internal consistency).Test plan
tests-integration/{ioredis,node-redis}/hash/hsetex.test.tscover: basic set, TTL-clear-on-overwrite,KEEPTTL,EX/PX/EXAT/PXAT(including immediate-expiry and last-field-removes-key),FNX/FXXall-or-nothing semantics, flexible token order, and the full error matrix (arity,WRONGTYPE, unknown token, mutual exclusion, invalid numfields, numfields/pair mismatch, invalid expire time, ordering of expire-time validation vs. condition).TEST_BACKEND=real)TEST_BACKEND=mock)npm run build,npm run lint,npm run test:allall pass (1102/1102 tests)docs/COMMANDS.mdanddocs/API.md(compatibility gate table) updated