Redis 8.10 introduces a new command called HIMPORT designed for efficient bulk insertion of hash data, avoiding the repeated transmission of field names required by HSET. Using the redis-rb Ruby client, the guide walks through preparing a field set with HIMPORT PREPARE, bulk-loading data with HIMPORT SET inside a pipeline, and discarding the field set afterward. A benchmark of one million records with three fields shows HIMPORT completing 11% faster than HSET, with larger gains expected for wider field sets due to bandwidth savings. Full demo source code is available on GitHub.
Table of contents
Getting startedWhy another way for importing hashes?How does it work?A simple benchmarkFull source codeQuestions this post answers
What is the Redis HIMPORT command and how is it different from HSET?
HIMPORT is a Redis command introduced for bulk hash insertion that avoids repeatedly sending field names with every write, unlike HSET. It works via sub-commands: HIMPORT PREPARE declares a named field set once, HIMPORT SET inserts records referencing that field set, and HIMPORT DISCARD removes it. This saves network bandwidth, especially with larger field sets. Track new Redis commands like this one as you plan data-import performance work, via daily.dev.
How much faster is HIMPORT than HSET for bulk inserts in Redis?
In a benchmark inserting one million records with a three-field hash, HIMPORT completed in 10.589 seconds versus 12.029 seconds for HSET, an 11% improvement. The gain comes from not resending field names on every call, so wider field sets are expected to show even larger improvements since more bandwidth is saved per record. Compare benchmark results like these before choosing a bulk-insert strategy in Redis, on daily.dev.
Do I need to re-prepare a HIMPORT field set after a Redis connection reconnects?
No, if himport_auto_prepare is set to true (the default) in the redis-rb client, the library maintains an internal registry of prepared field sets and automatically re-registers them after a reconnect. For pipelined bulk imports on a single connection, himport_auto_prepare can instead be set to false and the field set prepared explicitly within the pipeline. Keep track of client-library defaults like this one when adopting new Redis features, with daily.dev.