HIMPORT SET

HIMPORT SET key fieldset-name value [value ...]
Available since:
Redis Open Source 8.10.0
Time complexity:
O(N) where N is the number of fields in the fieldset.
ACL categories:
@write, @hash, @slow,
Compatibility:
Redis Software and Redis Cloud compatibility

Creates a hash from a fieldset previously defined with HIMPORT PREPARE, pairing the fieldset's field names with the supplied values by position.

Required arguments

key

The key to create. If the key already exists, it is overwritten.

fieldset-name

The name of a fieldset previously defined with HIMPORT PREPARE on the same connection.

value [value ...]

The field values, given in the same order as the field names were declared in the fieldset. The number of values must equal the number of fields in the fieldset.

Examples

> HIMPORT PREPARE u name email age
OK
> HIMPORT SET user:1 u alice [email protected] 30
OK
> HIMPORT SET user:2 u bob [email protected] 25
OK
> HGET user:1 name
"alice"
> HGET user:1 email
"[email protected]"
> HGET user:1 age
"30"

Details

HIMPORT SET creates or overwrites key as a hash whose fields are the field names of the prepared fieldset, each paired with the value at the same position. The number of values must match the number of fields in the fieldset.

The command returns an error if the fieldset has not been prepared on the current connection, or if the number of values does not match the fieldset's field count.

Keys created this way behave exactly like any other hash and work with all existing hash commands. Because they share a fixed set of field names, Redis can store them as compact hashes, keeping a single copy of the field names to reduce memory when many keys share the same layout.

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
❌ Standard
❌ Active-Active
❌ Standard
❌ Active-Active

Return information

See also

HIMPORT PREPARE | HSET | HIMPORT DISCARD

RATE THIS PAGE
Back to top ↑