Skip to content

Commit

Permalink
Support for the NOMKSTREAM option for XADD
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahaja committed May 10, 2024
1 parent 5abdf8a commit e5f58c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (m *Miniredis) cmdXadd(c *server.Peer, cmd string, args []string) {
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
maxlen := -1
minID := ""
makeStream := true
if strings.ToLower(args[0]) == "nomkstream" {
args = args[1:]
makeStream = false
}
if strings.ToLower(args[0]) == "maxlen" {
args = args[1:]
// we don't treat "~" special
Expand Down Expand Up @@ -101,7 +106,10 @@ func (m *Miniredis) cmdXadd(c *server.Peer, cmd string, args []string) {
return
}
if s == nil {
// TODO: NOMKSTREAM
if !makeStream {
c.WriteNull()
return
}
s, _ = db.newStream(key)
}

Expand Down
7 changes: 7 additions & 0 deletions cmd_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func TestStreamAdd(t *testing.T) {
)
})

t.Run("XADD NOMKSTREAM", func(t *testing.T) {
mustDo(t, c,
"XADD", "reallynosuchkey", "NOMKSTREAM", "MAXLEN", "~", "10", "*", "one", "1",
proto.Nil,
)
})

t.Run("error cases", func(t *testing.T) {
// Wrong type of key
mustOK(t, c,
Expand Down
9 changes: 9 additions & 0 deletions integration/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func TestStream(t *testing.T) {
"18446744073709551000-0",
"name", "Earth",
)
c.Do("XADD",
"reallynosuchkey",
"*",
"name", "Earth",
)
c.Error("ID specified", "XADD",
"planets",
"18446744073709551000-0", // <-- duplicate
Expand Down Expand Up @@ -125,6 +130,10 @@ func TestStream(t *testing.T) {
c.Do("MULTI")
c.Do("XADD", "planets", "MAXLEN", "four", "*", "name", "Mercury")
c.Do("EXEC")

c.Do("MULTI")
c.Do("XADD", "reallynosuchkey", "MAXLEN", "four", "*", "name", "Mercury")
c.Do("EXEC")
})
})

Expand Down

0 comments on commit e5f58c0

Please sign in to comment.