hset.3valkey - Man Page
Creates or modifies the value of a field in a hash.
Synopsis
HSET key field value [field value ...]
Description
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.
Reply
valkey-protocol(7) Integer reply: the number of fields that were added.
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.
Acl Categories
@fast @hash @write
History
- Available since: 2.0.0
- Changed in 4.0.0: Accepts multiple
fieldandvaluearguments.
Examples
127.0.0.1:6379> HSET myhash field1 "Hello" (integer) 1 127.0.0.1:6379> HGET myhash field1 "Hello" 127.0.0.1:6379> HSET myhash field2 "Hi" field3 "World" (integer) 2 127.0.0.1:6379> HGET myhash field2 "Hi" 127.0.0.1:6379> HGET myhash field3 "World" 127.0.0.1:6379> HGETALL myhash 1) "field1" 2) "Hello" 3) "field2" 4) "Hi" 5) "field3" 6) "World"
See Also
hdel(3valkey), hexists(3valkey), hget(3valkey), hgetall(3valkey), hincrby(3valkey), hincrbyfloat(3valkey), hkeys(3valkey), hlen(3valkey), hmget(3valkey), hrandfield(3valkey), hscan(3valkey), hsetnx(3valkey), hstrlen(3valkey), hvals(3valkey)