Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

HSET

Last updated
HSET key field value [field value ...]
Group
Hash
Complexity
O(1) for each field/value pair given
Arity
-4 (at least 4 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

HSET writes each field and value pair into the hash stored at key. A missing key is created as an empty hash first. A field that already exists gets the new value, and any time to live set on that field with HEXPIRE or a related command is removed. To keep field TTLs while writing, use HSETEX with KEEPTTL.

Fields are written left to right, so if the same field appears twice the last value wins.

Case RESP2 RESP3
Success Integer: the number of fields that were newly created (updated fields are not counted) Same

Errors:

  • WRONGTYPE if key holds a value that is not a hash. Nothing is written.
  • ERR wrong number of arguments for 'hset' command if no pair is given or a field has no value.
127.0.0.1:6379> HSET user:1 name "Ada" lang "en"
(integer) 2
127.0.0.1:6379> HSET user:1 lang "fr" city "Paris"
(integer) 1
127.0.0.1:6379> HGET user:1 lang
"fr"

Same arguments and replies as Redis 7.4 and Valkey 8.

HGET, HSETNX, HSETEX, HMSET, HDEL, HGETALL