HSET
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.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the number of fields that were newly created (updated fields are not counted) | Same |
Errors:
WRONGTYPEifkeyholds a value that is not a hash. Nothing is written.ERR wrong number of arguments for 'hset' commandif no pair is given or a field has no value.
Examples
Section titled “Examples”127.0.0.1:6379> HSET user:1 name "Ada" lang "en"(integer) 2127.0.0.1:6379> HSET user:1 lang "fr" city "Paris"(integer) 1127.0.0.1:6379> HGET user:1 lang"fr"Compatibility
Section titled “Compatibility”Same arguments and replies as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.