# XLEN

> Return the number of entries in a stream.

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

```
XLEN key
```

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

`XLEN` returns how many entries the stream at `key` holds. Deleted and trimmed
entries are not counted.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Stream exists | Integer: the number of entries | Integer |
| Key does not exist | Integer `0` | Integer `0` |

`WRONGTYPE` if the key holds another type.

## Examples

```
127.0.0.1:6379> XADD sensor 1700000000000-0 temp 21.5
"1700000000000-0"
127.0.0.1:6379> XADD sensor 1700000000001-0 temp 21.7
"1700000000001-0"
127.0.0.1:6379> XLEN sensor
(integer) 2
127.0.0.1:6379> XLEN nosuchstream
(integer) 0
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[XADD](https://docs.hotkv.com/commands/xadd/index.md), [XINFO STREAM](https://docs.hotkv.com/commands/xinfo-stream/index.md), [XTRIM](https://docs.hotkv.com/commands/xtrim/index.md)