HSET

Syntax

  1. HSET key field value [field value ...]

Time complexity: O(1) for each field/value pair added, so O(N) to add N field/value pairs when the command is called with multiple field/value pairs.

Sets the specified fields to their respective values in the hash stored at key.

This command overwrites the values of specified fields that exist in the hash. If key doesn’t exist, a new key holding a hash is created.

Return

Integer reply: The number of fields that were added.

Examples

  1. dragonfly> HSET myhash field1 "Hello"
  2. (integer) 1
  3. dragonfly> HGET myhash field1
  4. "Hello"
  5. dragonfly> HSET myhash field2 "Hi" field3 "World"
  6. (integer) 2
  7. dragonfly> HGET myhash field2
  8. "Hi"
  9. dragonfly> HGET myhash field3
  10. "World"
  11. dragonfly> HGETALL myhash
  12. 1) "field1"
  13. 2) "Hello"
  14. 3) "field2"
  15. 4) "Hi"
  16. 5) "field3"
  17. 6) "World"