1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-07-02 11:43:40 +02:00
This commit is contained in:
Henrik Hautakoski 2023-03-13 20:56:19 +01:00
parent 531a2d3d17
commit 2f76057f2e
4 changed files with 238 additions and 0 deletions

View file

@ -0,0 +1,35 @@
package redis_stream
import (
"context"
"github.com/go-redis/redis/v8"
)
type Stream struct {
Key string
id string
}
func (s Stream) Read(client *redis.Client, ctx context.Context) error {
args := &redis.XReadArgs{
Streams: []string{s.Key, s.id},
}
streams, err := client.XRead(ctx, args).Result()
if err != nil {
return err
}
for _, strm := range streams {
l := len(strm.Messages)
if l > 0 {
id = strm.Messages[l-1].ID
// Write id to redis
if err := rs.client.Set(rs.ctx, strm.Stream+":id", rs.id, 0).Err(); err != nil {
return err
}
}
}
}