# HLEN

> Get the number of fields in a hash.

URL: https://docs.hotkv.com/commands/hlen/

```
HLEN key
```

- Group: Hash
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`HLEN` returns how many fields the hash stored at `key` holds.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Hash exists | Integer: the number of fields | Same |
| Key does not exist | Integer `0` | Same |

`HLEN` replies with a `WRONGTYPE` error if `key` holds a value that is not a
hash.

## Examples

```
127.0.0.1:6379> HSET user:1 name "Ada" lang "en"
(integer) 2
127.0.0.1:6379> HLEN user:1
(integer) 2
127.0.0.1:6379> HLEN nosuchkey
(integer) 0
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[HKEYS](https://docs.hotkv.com/commands/hkeys/index.md), [HVALS](https://docs.hotkv.com/commands/hvals/index.md), [HSTRLEN](https://docs.hotkv.com/commands/hstrlen/index.md),
[HGETALL](https://docs.hotkv.com/commands/hgetall/index.md)