mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
icingaredis.Client: Add StreamLastId()
This commit is contained in:
parent
26c889ad66
commit
b05a00a8d5
1 changed files with 16 additions and 0 deletions
|
|
@ -145,3 +145,19 @@ func (c *Client) HMYield(ctx context.Context, key string, count int, concurrent
|
|||
|
||||
return pairs, com.WaitAsync(g)
|
||||
}
|
||||
|
||||
// StreamLastId fetches the last message of a stream and returns its ID.
|
||||
func (c *Client) StreamLastId(ctx context.Context, stream string) (string, error) {
|
||||
lastId := "0-0"
|
||||
|
||||
messages, err := c.XRevRangeN(ctx, stream, "+", "-", 1).Result()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, message := range messages {
|
||||
lastId = message.ID
|
||||
}
|
||||
|
||||
return lastId, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue