Skip to content

[Redis 8.10] Add HIMPORT (Hinted Hash Templates) support - #4667

Merged
ggivo merged 15 commits into
masterfrom
himport-8.10-v3
Aug 7, 2026
Merged

ggivo merged 15 commits into
masterfrom
himport-8.10-v3

Conversation

@a-TODO-rov

@a-TODO-rov a-TODO-rov commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Adds client support for the Redis 8.10 HIMPORT command family (Hinted Hash Templates). When many hashes share the same field names, a client names the field set once and then creates keys sending only their values, cutting client→server traffic and letting the server store the keys template-encoded. The keys produced are ordinary hashes.

The public surface is a single managed command, himportSet, plus a HashImport template:

try (HashImport fs = HashImport.of("name", "email", "age")) {
    jedis.himportSet("u:1", fs, "alice", "a@x.com", "25");
    jedis.himportSet("u:2", fs, "bob",   "b@x.com", "30");
}

A fieldset is per-physical-connection server state, so PREPARE/DISCARD are managed transparently rather than exposed: each himportSet lazily prepares the template on whichever connection runs it, and cleanup happens when connections are next borrowed.

Design

  • himportSet lives on the existing hash interfaces (HashCommands, HashBinaryCommands, and their HashPipeline* variants), not a separate interface — it is an ordinary hash command from the caller's point of view. Implemented on UnifiedJedis, legacy Jedis, and standalone Pipeline.
  • Goes through the normal CommandExecutor. The himportSet CommandObject carries a preProcessHook (Consumer<Connection>) that Connection.executeCommand runs immediately before sending the command. The hook injects a lazy PREPARE on the chosen connection when the fieldset is not yet prepared there. Because the command still travels the executor path, cluster MOVED/ASK redirection, retry, and failover all re-run the hook on whatever connection the executor lands on. The command is never routed around the executor.
  • Lazy prepare-before-use, tracked per connection. Each Connection keeps a note of the fieldsets prepared on it (name → weak reference to the HashImport), reset whenever the socket is (re)connected or broken.
  • Cleanup by borrow-time reconciliation. HashImport.close() just marks the template discarded, before next command execution on a connection discards any fieldset on that connection whose template was closed or garbage-collected, and drops it from the note.
  • Cluster works per node with no broadcast: himportSet routes by the key's slot and self-prepares on that node; each node pool reconciles independently.

Behavior

  • himportSet validates the value count against the template's field count and rejects a discarded template, both client-side.
  • Legacy Jedis rejects himportSet inside MULTI/pipeline via the existing checkIsInMultiOrPipeline() guard.
  • Pipeline: supported only on a single-connection Pipeline, which buffers PREPARE ahead of the SET. A transaction (MULTI) and a cluster pipeline throw UnsupportedOperationException — a keyless PREPARE cannot be routed by slot, and injecting it into a transaction would desync EXEC.
  • Marked @Experimental (@since 8.0); HIMPORT ships only in Redis 8.10+.

Testing

All against a live Redis 8.10 RC environment, gated with @EnabledOnCommand("HIMPORT"):

  • HashImportTest — template validation (empty/null/duplicate fields, defensive byte[] copy, close()), unit.
  • HIMPORT cases folded into the existing hash suites: HashesCommandsTestBase (standalone + cluster runners), legacy HashesCommandsTest, and HashesPipelineCommandsTest.
  • HashImportReconciliationIT — white-box tests for the per-connection mechanism: borrow-time discard of a closed fieldset, discard of a garbage-collected one, and note reset + lazy re-prepare after a broken connection.

Notes

  • No public himportPrepare/himportDiscard/himportDiscardAll; the lifecycle is internal.
  • Pooled reclamation of server-side state is lazy — a discarded fieldset on an idle pooled connection is reclaimed only when that connection is next borrowed (or recycled). It is inert until then, since fieldset names are unique per template.

Note

Medium Risk
Touches core command execution (Connection, CommandObject, cluster redirection) and connection-local protocol state; behavior is well-tested but mistakes could affect non-HIMPORT paths (hooks, ASK ordering).

Overview
Adds experimental client support for Redis 8.10 HIMPORT (Hinted Hash Templates): a reusable HashImport field-set template and himportSet on the existing hash command surfaces (HashCommands, pipelines, UnifiedJedis/Jedis).

The client hides connection-local PREPARE / DISCARD lifecycle. himportSet travels the normal executor path with a CommandObject pre-process hook that lazily sends HIMPORT PREPARE on the connection that will run the SET. Per-connection HimportConnectionState tracks prepared fieldsets; closing a template queues discards that are flushed before the next command on each touched connection. Single-connection Pipeline buffers internal PREPARE replies so syncAndReturnAll() only returns user commands; MULTI and cluster pipelines reject himportSet.

Cluster ASK retries now append ASKING as a pre-process hook (after any HIMPORT PREPARE) so one-shot ASKING is not consumed early. RESET and reconnect clear client HIMPORT state.

Adds docs/hash-import.md, protocol HIMPORT keywords, and unit/integration/mock tests.

Reviewed by Cursor Bugbot for commit e41fdb4. Bugbot is set up for automated code reviews on this repo. Configure here.

@a-TODO-rov
a-TODO-rov requested review from atakavci and ggivo July 31, 2026 16:11
@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Test Results

  206 files  ± 0    206 suites  ±0   8m 12s ⏱️ +53s
8 092 tests +36  8 024 ✅ +1 176  68 💤  - 1 140  0 ❌ ±0 
8 112 runs  +48  8 044 ✅ +1 196  68 💤  - 1 148  0 ❌ ±0 

Results for commit e41fdb4. ± Comparison against base commit f2fe13e.

This pull request removes 2 and adds 38 tests. Note that renamed tests count towards both.
redis.clients.jedis.commands.unified.search.FTHybridCommandsTestBase$SupportedScorersTest ‑ testScorer(Scorer, double, double)[1]
redis.clients.jedis.commands.unified.search.FTHybridCommandsTestBase$SupportedScorersTest ‑ testScorer(Scorer, double, double)[2]
redis.clients.jedis.UnboundRedisClusterClientTest ‑ testAskResponseWithHimportSet
redis.clients.jedis.commands.jedis.HashesCommandsTest[1] ‑ himportSet()[1]
redis.clients.jedis.commands.jedis.HashesCommandsTest[2] ‑ himportSet()[2]
redis.clients.jedis.commands.jedis.HashesCommandsTest[3] ‑ himportSet()[3]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[1] ‑ himportSet()[1]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[1] ‑ himportSetRejectsDiscardedTemplate()[1]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[1] ‑ himportSetRejectsWrongValueCount()[1]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[1] ‑ himportSetReusesTemplateAcrossKeys()[1]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[2] ‑ himportSet()[2]
redis.clients.jedis.commands.unified.client.RedisClientHashesCommandsTest[2] ‑ himportSetRejectsDiscardedTemplate()[2]
…

♻️ This comment has been updated with latest results.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8ae031ac2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c317db290b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ggivo ggivo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding a few more findings

I think most review bot finding are also legitimate and need to be addressed

A long-lived template kept strong references to every connection it
was prepared on, retaining connections the pool had already destroyed.

Record them in ConnectionRegistry instead: a weak-reference registry
(same class as the maintenance-events branch, PR #4668) that prunes
collected connections, so close() visits only live ones. close() is
now idempotent, and registerConnection re-checks discarded afterwards
so a close() racing first use cannot leave the fieldset undiscarded.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14725896d1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

On an ASK redirect the executor sent ASKING out-of-band before the
command; a command-intrinsic hook such as HIMPORT's lazy PREPARE then
consumed the one-shot ASKING state, redirecting the command again
until attempts were exhausted.

CommandObject is now immutable and carries an ordered list of
pre-process hooks; withPreProcessHook() returns a modified copy.
ClusterCommandExecutor appends the ASKING hook to a copy of the
redirected command, so the wire order is PREPARE, ASKING, SET and
ASKING applies to the command itself.

Covered by CommandObjectTest and testAskResponseWithHimportSet
(himportSet on a migrating slot), verified against a live cluster.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b5ccdde23

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Discard reconciliation ran only in ConnectionFactory.activateObject, so
legacy JedisPool/JedisSentinelPool and direct unpooled connections never
issued queued HIMPORT DISCARDs, accumulating server-side fieldsets. A
discard failure was also swallowed there after marking the connection
broken, handing a dead connection to the borrower.

Move reconciliation to the Connection.executeCommand entry points: one
choke point covers every path, gated by a single volatile read. Pending
discards go out as one packed write with replies drained in one pass;
error replies are ignored while connection failures propagate to the
retry machinery. activateObject is a no-op again.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7594f06. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7594f066ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

The HIMPORT PREPARE injected before a first-use himportSet was buffered
like a user command, so syncAndReturnAll() returned an extra OK and
shifted the positions callers rely on.

Pipeline responses are now QueuedResponse entries flagged internal or
user at creation; internal commands are buffered via
appendInternalCommand and their replies, while still read in wire
order, are filtered from syncAndReturnAll(). sync() is unchanged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 974e218f35

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

ggivo added 4 commits August 6, 2026 17:05
setBroken() cleared the connection's HIMPORT state, but it may be
called by threads that do not own the connection (forceDisconnect,
maintenance paths), racing the owner's unsynchronized prepared set.
The clear was also unnecessary: broken connections are dropped on
every pooled and executor path, never reused.

Remove the reset from setBroken(); connect() alone resets the state
(renamed HimportConnectionState.reset()), which only the owner thread
runs. Drop the legacy integration tag from HashImportReconcileIT -
the IT suffix alone routes it to failsafe.
Empty field names slipped past validation despite the documented
contract, deferring the failure to HIMPORT PREPARE on the server.
Reject "" and zero-length byte[] in the shared build step.

Replace HashImportReconcileIT (legacy-client, introspection-based)
with HimportLifecycleMockTest: a TcpMockServer command log pins the
wire contract - PREPARE once per connection ahead of the first SET,
queued DISCARDs of closed templates drained right before the next
command, batched. Reconciliation runs at the shared
Connection.executeCommand choke point, so provisioning-path variants
added no logic coverage.
RESET drops connection-scoped fieldsets server-side, but the client
kept its prepared note, so later himportSet calls skipped PREPARE and
failed until reconnect. Jedis.reset() now resets the connection's
HIMPORT state; clearing in finally is harmless on failure (at worst
one extra re-PREPARE). Raw sendCommand(RESET) is intentionally out of
scope.
New public API needs release provenance in the generated docs; also
complete the truncated javadoc sentence.
Every himportSet call eagerly built the PREPARE command object -
fieldset name plus all field tokens - just to capture it in the
pre-process hook, then discarded it whenever the connection was
already prepared, the common case in bulk-import loops.

Assemble the PREPARE arguments inside prepareBeforeUse instead, on
the not-prepared branch only; the steady-state path allocates
nothing PREPARE-related. Wire order covered by
HimportLifecycleMockTest.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8237e27775

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +309 to 311
himportSendPendingDiscards();
sendCommand(args);
return getOne();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear HIMPORT state on low-level RESET

When the same physical connection is reset through the public low-level path, e.g. connection.executeCommand(Protocol.Command.RESET) before returning to a Jedis wrapper, Redis drops the connection-local HIMPORT fieldsets but this method leaves himportState marked as prepared. Fresh evidence is that this patch only clears the state in Jedis.reset(), so the next managed himportSet on that connection skips PREPARE and fails as an unprepared fieldset; clear the HIMPORT state when these Connection command paths issue RESET as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

already answered

Expand the himportSet javadoc on all four command interfaces with the
verified contract: existing hashes are replaced, wrong value count and
closed templates fail eagerly, transactions and cluster pipelines are
unsupported, PREPARE is injected per pooled connection.

Add docs/hash-import.md under User Guide covering usage, pipelining,
cluster behavior and limitations, with a compiled example
(HashImportUsage) mirroring the doc snippets, verified against a live
Redis 8.10.
@ggivo
ggivo force-pushed the himport-8.10-v3 branch from 8237e27 to 634c86a Compare August 7, 2026 10:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e41fdb472e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ggivo
ggivo merged commit d2f4d5d into master Aug 7, 2026
14 of 15 checks passed
@ggivo ggivo added the feature label Aug 7, 2026
@ggivo ggivo added this to the 8.0.0 milestone Aug 7, 2026
@ggivo
ggivo deleted the himport-8.10-v3 branch August 12, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants