example/himport/README.md
Fast hash ingestion with the HIMPORT command family (hinted hash templates, Redis 8.10+).
Experimental. The HIMPORT commands and the typed go-redis API around them are experimental and may change in a future release.
HIMPORT PREPARE registers an ordered list of field names (a fieldset)
inside a connection's session; HIMPORT SET then creates hashes by sending
only the values, paired positionally with the prepared fields. The server
stores such hashes in a memory-efficient template encoding where the shared
field names are kept only once.
Fieldsets are scoped to a single physical connection on the server. go-redis
hides that from pooled callers: fieldsets registered with HImportPrepare
are remembered client-side and the PREPARE is replayed lazily — at most
once per connection session — on whichever pooled connection executes an
HImportSet, including inside pipelines and transactions. A connection that
lost its session state (RESET, reconnect) is re-prepared transparently.
These guarantees apply only to the typed methods (HImportPrepare,
HImportSet, HImportDiscard, HImportDiscardAll). Any HIMPORT command
sent through generic command interfaces — Do, raw Cmd values, or similar
low-level access — bypasses the client-side registry entirely: nothing is
replayed onto other connections, no such fieldset is not recovered, and
discards do not propagate. Such commands act on the session of whichever
connection happens to execute them, so they are only meaningful on a
dedicated connection (client.Conn()) managed explicitly by the caller.
The example walks through:
HSET pipelinesOBJECT ENCODING template encodings and the
INFO memory template countersRequires a Redis 8.10+ server built with the hinted hash templates feature
(the example exits with a message otherwise). The address defaults to
localhost:6379 and can be overridden with REDIS_ADDR:
go run .
# or
REDIS_ADDR=localhost:6390 go run .