HLEN - Count the Number of Fields in a Hash in Redis

Feature thumb course thumb

When you call the HLEN command on a hash in Redis, it will return the number of fields for that hash. If the hash does not exist or does not have any fields it will return 0.

127.0.0.1:6379> HSET company_locations arizona Scottsdale
(integer) 1
127.0.0.1:6379> HSET company_locations washington Seattle
(integer) 1
127.0.0.1:6379> HSET company_locations california Anaheim
(integer) 1
127.0.0.1:6379> HLEN company_locations
(integer) 3
127.0.0.1:6379> HDEL company_locations washington
(integer) 1
127.0.0.1:6379> HLEN company_locations
(integer) 2
127.0.0.1:6379> HLEN not_a_hash
(integer) 0