Skip to content

Commit

Permalink
Merge pull request #375 from Jahaja/xadd-nomkstream
Browse files Browse the repository at this point in the history
Support for the NOMKSTREAM option for XADD
  • Loading branch information
alicebob authored May 12, 2024
2 parents 5abdf8a + 73e4e17 commit 890a1c8
Show file tree
Hide file tree
Showing 3 changed files with 34 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
15 changes: 15 additions & 0 deletions cmd_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ func TestStreamAdd(t *testing.T) {
)
})

t.Run("XADD NOMKSTREAM", func(t *testing.T) {
mustDo(t, c,
"XADD", "reallynosuchkey", "NOMKSTREAM", "*", "one", "1",
proto.Nil,
)
mustDo(t, c,
"XADD", "reallynosuchkey", "NOMKSTREAM", "MINID", "1672545848004-0", "*", "one", "1",
proto.Nil,
)
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
10 changes: 10 additions & 0 deletions integration/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func TestStream(t *testing.T) {
"18446744073709551000-0",
"name", "Earth",
)
c.Do("XADD",
"reallynosuchkey",
"NOMKSTREAM",
"*",
"name", "Earth",
)
c.Error("ID specified", "XADD",
"planets",
"18446744073709551000-0", // <-- duplicate
Expand Down Expand Up @@ -125,6 +131,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", "NOMKSTREAM", "MAXLEN", "four", "*", "name", "Mercury")
c.Do("EXEC")
})
})

Expand Down

0 comments on commit 890a1c8

Please sign in to comment.