1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-14 01:21:30 +03:00

Add support for XREAD last entry (#3005)

* add support for XREAD last entry

* handle reading from multiple streams

* add test to ensure we block for empty stream

* small tweak

* add an option to XReadArgs instead

* modify test comment

* small preallocation optimization

* Changed argument to generic ID, skip tests on Enterprise

* Fix test case

* Updated expiration command

---------

Co-authored-by: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com>
Co-authored-by: vladvildanov <divinez122@outlook.com>
This commit is contained in:
b1ron
2024-06-20 10:25:51 +02:00
committed by GitHub
parent 445d2667eb
commit 3975cd5380
2 changed files with 82 additions and 3 deletions

View File

@ -137,10 +137,11 @@ type XReadArgs struct {
Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
Count int64
Block time.Duration
ID string
}
func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
args := make([]interface{}, 0, 6+len(a.Streams))
args := make([]interface{}, 0, 2*len(a.Streams)+6)
args = append(args, "xread")
keyPos := int8(1)
@ -159,6 +160,11 @@ func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
for _, s := range a.Streams {
args = append(args, s)
}
if a.ID != "" {
for range a.Streams {
args = append(args, a.ID)
}
}
cmd := NewXStreamSliceCmd(ctx, args...)
if a.Block >= 0 {