Skip to content

Commit

Permalink
fix 'XREAD ... $' on a non-existing stream
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Apr 19, 2023
1 parent 2f1aeb3 commit 4be3b82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,12 @@ parsing:
return
} else if id == "$" {
db := m.DB(getCtx(c).selectedDB)
opts.ids[i] = db.streamKeys[opts.streams[i]].lastID()
stream, ok := db.streamKeys[opts.streams[i]]
if ok {
opts.ids[i] = stream.lastID()
} else {
opts.ids[i] = "0-0"
}
}
}
args = nil
Expand Down
13 changes: 13 additions & 0 deletions integration/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ func TestStream(t *testing.T) {
wg.Wait()
c.Do("XREAD", "BLOCK", "1000", "STREAMS", "pl", "$")
})

// special '$' ID on non-existing stream
testRaw2(t, func(c, c2 *client) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
time.Sleep(10 * time.Millisecond)
c2.Do("XADD", "pl", "60-1", "nosuch", "Mercury")
wg.Done()
}()
wg.Wait()
c.Do("XREAD", "BLOCK", "1000", "STREAMS", "nosuch", "$")
})
})
}

Expand Down

0 comments on commit 4be3b82

Please # to comment.