w3resource

Redis Hash: HKEYS

Redis HKEYS Command

Redis HKEYS command is used to get all field names in the hash stored at key.

Here are some common uses and scenarios for the "HKEYS" command:

  • Field Enumeration: List all the field names in a hash for inspection or processing.
  • Data Analysis: Analyze or debug the structure and contents of a hash.
  • Configuration Management: Retrieve all configuration keys stored in a hash.
  • Session Attributes: List all session attributes or user properties stored in a hash.
  • Dynamic Field Handling: Use in applications where field names in hashes are dynamic or need to be processed programmatically.

Syntax:

HKEYS KEY_NAME FIELD_NAME INCR_BY_NUMBER  

Available since

2.0.0.

Return Value

Array reply, a list of fields in the hash, or an empty list when a key does not exist.

Return Value Type

Integer

Example: Redis HKEYS

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> HSET langhash lang3 "Python"
(integer) 1
127.0.0.1:6379> HSET langhash lang4 "Golanguage"
(integer) 1
127.0.0.1:6379> HKEYS langhash
1) "lang1"
2) "lang2"
3) "lang3"
4) "lang4"

Example: Redis HKEYS another example

127.0.0.1:6379> HKEYS user
1) "email"
2) "lang"
3) "gender"
4) "visits"
5) "height"
127.0.0.1:6379> HMSET user-x name Sweaty gender Female lang English
OK
127.0.0.1:6379> HKEYS user-x
1) "name"
2) "gender"
3) "lang"

Previous: HINCRBYFLOAT
Next: HLEN



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/redis/redis-hkeys-key.php