Hashes Hset
# Redis Hset Command
[!(#) Redis Hashes](#)
The Redis Hset command is used to assign a value to a field in a hash table.
If the hash table doesn't 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 of the redis Hset command is as follows:
redis 127.0.0.1:6379> HSET KEY_NAME FIELD VALUE
### Available Version
>= 2.0.0
### Return Value
Returns 1 if the field is a new field in the hash table and the value was set successfully. Returns 0 if the field already existed in the hash table and the old value was 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" # Set a new field(integer) 1 redis 127.0.0.1:6379>HSET website google "www.google.com" # Overwrite an existing field(integer) 0
[!(#) Redis Hashes](#)
YouTip