mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-02 11:43:40 +02:00
WIP
This commit is contained in:
parent
531a2d3d17
commit
2f76057f2e
4 changed files with 238 additions and 0 deletions
35
transport/redis_stream/stream.go
Normal file
35
transport/redis_stream/stream.go
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue