What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

HLEN

Returns the number of fields in a hash.

Usage
HLEN key
Complexity
O(1)
Since
2.0.0
ACL Categories
@fast, @hash, @read
Command flags
READONLY, FAST

Returns the number of fields contained in the hash stored at key.

Examples

127.0.0.1:6379> HSET myhash field1 "Hello"
(integer) 1
127.0.0.1:6379> HSET myhash field2 "World"
(integer) 1
127.0.0.1:6379> HLEN myhash
(integer) 2

Replies

RESP2

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

RESP3

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