w3resource

Redis Hash: HSET

HSET key field value

Redis HSET command is used to set the field in the hash stored at key to value. If the key does not exist, a new key holding a hash is created. If the field already exists in the hash, it is overwritten.

Syntax:

HSET KEY_NAME FIELD VALUE   

Return Value

Integer reply

  • 1 if the field is a new field in the hash and value was set.
  • 0 if the field already exists in the hash and the value was updated.

Example: Redis HSET

127.0.0.1:6379> HSET langhash lang1 "PHP"
(integer) 1
127.0.0.1:6379> HSET langhash lang2 "Javascript"
(integer) 1
127.0.0.1:6379> HGET langhash lang1
"PHP"
127.0.0.1:6379> HGET langhash lang2
"Javascript"

Example: Redis HSET another example

127.0.0.1:6379> HSET user email [email protected]
(integer) 1
127.0.0.1:6379> HSET user lang English
(integer) 1
127.0.0.1:6379> HSET user gender Male
(integer) 1
127.0.0.1:6379> HGETALL user
1) "email"
2) "[email protected]"
3) "lang"
4) "English"
5) "gender"
6) "Male"

Previous: HMSET
Next: HSETNX



Follow us on Facebook and Twitter for latest update.