HIMPORT
HIMPORT
- Available since:
- Redis Open Source 8.10.0
- Time complexity:
- Depends on subcommand.
- ACL categories:
-
@hash,@slow,
HIMPORT is a container command for session-based bulk hash import. Its subcommands let a client import many hashes that share the same field names efficiently by declaring those field names once and then sending only the values for each key.
The subcommands are:
HIMPORT PREPARE— define a session-local fieldset that names an ordered list of field names.HIMPORT SET— create a hash from a prepared fieldset and a list of values.HIMPORT DISCARD— remove a single fieldset by name.HIMPORT DISCARDALL— remove every fieldset held by the connection.
Details
A fieldset is a named, ordered list of field names that is scoped to the client connection: it is not visible to other clients and is discarded when the connection closes or the client issues the RESET command. A connection can prepare several fieldsets, each under its own name, and refer to them by name in later commands.
The typical workflow is to declare a fieldset once with HIMPORT PREPARE, then create many keys from it with HIMPORT SET, sending only the values each time:
HIMPORT PREPARE u name email age
HIMPORT SET user:1 u alice [email protected] 30
HIMPORT SET user:2 u bob [email protected] 25
Because every key created this way shares one fixed set of field names, HIMPORT reduces the network traffic and per-command work compared with running HSET once per key. Redis also uses the shared field names as a hint to store the keys as compact hashes, an internal encoding that keeps a single copy of the field names and reduces memory when many keys share the same layout. This encoding does not change the behavior or replies of any existing hash command.