English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Hset Command

Redis Hashes (Hash)

The Redis Hset command is used to assign values to fields in hash tables.

If the hash table does not exist, a new hash table will be created and the HSET operation will be performed.

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

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

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

Online 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 domain
(integer) 1
redis 127.0.0.1:6379>HSET website google "www.google.com" # Override an old domain
(integer) 0

Redis Hashes (Hash)