Redis Hset Command
The Redis Hset command is used to set the value of a field in a hash table.
If the hash table does not exist, a new hash table is created and the HSET operation is performed.
If the field already exists in the hash table, the old value will be overwritten.
Syntax
The basic syntax for the redis Hset command is as follows:
redis 127.0.0.1:6379> HSET KEY_NAME FIELD VALUE
Available Versions
= 2.0.0
Return Value
Returns 1 if the field is a new field in the hash table and the value is set successfully. Returns 0 if the field already exists in the hash table and the old value has been overwritten by the new value.
Examples
redis 127.0.0.1:6379> HSET myhash field1 "foo"
OK
redis 127.0.0.1:6379> HGET myhash field1
"foo"
redis 127.0.0.1:6379> HSET website google "www.g.cn" # Sets a new field
(integer) 1
redis 127.0.0.1:6379> HSET website google "www.google.com" # Overwrites an existing field
(integer) 0