w3resource

Redis Hash: HLEN

Redis HLEN Command

Redis HLEN command is used to get the number of fields contained in the hash stored at key.

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

  • Field Count Retrieval: Determine the number of fields in a hash.
  • Data Validation: Validate the size of the hash for consistency checks.
  • Resource Monitoring: Monitor the number of fields for performance and resource usage.
  • Conditional Logic: Perform actions based on the number of fields in a hash.
  • Inventory and Configuration: Check the quantity of items or settings stored in a hash.

Syntax:

HLEN KEY_NAME  

Available since

2.0.0.

Return Value

Integer reply, the number of fields in the hash, or 0 when a key does not exist.

Return Value Type

Integer

Example: HLEN

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> HLEN langhash
(integer) 4

Example: Redis HLEN another example

127.0.0.1:6379> HMSET user-x name Sweaty gender Female lang English
OK
127.0.0.1:6379> HLEN user-x
(integer) 3

Previous: HKEYS
Next: HMGET



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://w3resource.com/redis/redis-hlen-key.php