Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Hset Command

Redis Hset Command

Redis Hash

The Redis Hset command is used to set the value of a field in the hash.

If the hash does not exist, a new hash is created and the HSET operation is performed.

If the field already exists in the hash, the old value is 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 and the value was set successfully. Returns 0 if the field already existed and the old value was overwritten by the new value.

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