ospider
ospider

Reputation: 10421

How to get the lag size of a consumer group in redis stream?

Suppose I have stream mystream, and a group mygroup, how do I get the length of unconsumed messages?

Upvotes: 4

Views: 1272

Answers (2)

Vimtekken
Vimtekken

Reputation: 71

Use XINFO GROUPS

The command XINFO GROUPS mygroup will provide a field in the response for lag.

According to the documentation:

lag: the number of entries in the stream that are still waiting to be delivered to the group's consumers, or a NULL when that number can't be determined.

If you are wondering why lag can be null:

There are two special cases in which this mechanism is unable to report the lag:

  • A consumer group is created or set with an arbitrary last delivered ID (the XGROUP CREATE and XGROUP SETID commands, respectively). An arbitrary ID is any ID that isn't the ID of the stream's first entry, its last entry or the zero ("0-0") ID.

  • One or more entries between the group's last-delivered-id and the stream's last-generated-id were deleted (with XDEL or a trimming operation).

In both cases, the group's read counter is considered invalid, and the returned value is set to NULL to signal that the lag isn't currently available.

More details can be found at https://redis.io/commands/xinfo-groups/

Upvotes: 0

Itamar Haber
Itamar Haber

Reputation: 49962

No, there is no way to do that afaik.

It is possible to get the last message ID delivered in a group and in a stream with the XINFO GROUPS and XINFO STREAM commands, respectively.

However, there is no command that returns the length of a stream subrange. Such command, was it to exist, would probably require linear time complexity and in that case, it will probably not be implemented.

Upvotes: 1

Related Questions