Latest web development tutorials

Redis Hset command

Redis hash (Hash)

Redis Hset command is used to hash table field assignment.

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

If the field already exists in the hash table, the old value will be overwritten.

grammar

redis Hset basic command syntax 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 in the hash table a new field, and set the value of success, 1 is returned. If the hash table already exists in the domain field and the old value is overwritten with the new value, return 0.

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

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

Redis hash (Hash)