XLen returns the number of elements in a given stream. It takes the name of the stream as an argument and returns the number of elements in the stream. Parameters: name: The name of the stream. Returns: int: The number of elements (messages) in the stream. error: An error if any occurred duri
(name string)
| 329 | // - It retrieves the messages from s.streams.Messages. |
| 330 | // - It returns the number of messages in the stream. |
| 331 | func (s *StreamStructure) XLen(name string) (int, error) { |
| 332 | // Get the stream |
| 333 | encodedStreams, err := s.db.Get([]byte(name)) |
| 334 | if err != nil { |
| 335 | return 0, err |
| 336 | } |
| 337 | |
| 338 | // Decode the streams |
| 339 | if err = s.decodeStreams(encodedStreams, s.streams); err != nil { |
| 340 | return 0, err |
| 341 | } |
| 342 | |
| 343 | // Get the messages |
| 344 | messages := s.streams.Messages |
| 345 | |
| 346 | return len(messages), nil |
| 347 | } |
| 348 | |
| 349 | // XRange returns the messages in the stream. |
| 350 | // It takes the name of the stream, the start index, and the stop index as arguments, |