Usage
Parameters
The key of the stream.
Response
The number of entries in the stream.Returns
0 if the key doesn’t exist or is an empty stream.Examples
Get stream length
Check if stream exists
Monitor stream growth
Track stream size with trimming
Check multiple streams
Stream capacity check
Compare stream sizes
Conditional operations based on size
Calculate stream growth rate
Important Notes
Empty Streams
XLEN returns0 for both non-existent keys and empty streams:
Performance
- XLEN is an O(1) operation (constant time)
- Very fast even for streams with millions of entries
- Safe to call frequently for monitoring
After Trimming
XLEN reflects the current number of entries after any trimming:Use Cases
- Monitoring: Track stream size over time
- Capacity planning: Check if trimming is needed
- Metrics: Calculate processing rates
- Validation: Verify entries were added successfully
- Debugging: Understand stream state