Redis Hset Command

Redis Hash

Redis Hset command is used to assign values to fields 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 of 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

If the field is a new field in the hash table and the value was set successfully, return 1. If the field already exists in the hash table and the old value has been overwritten by the new value, return 0.

Example

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"       # 设置一个新域
(integer) 1

redis 127.0.0.1:6379>HSET website google "www.google.com" # 覆盖一个旧域
(integer) 0

Redis Hash

Other Extensions