diff --git a/cmd_stream.go b/cmd_stream.go index 5cd8c26..b6d0034 100644 --- a/cmd_stream.go +++ b/cmd_stream.go @@ -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 @@ -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) } diff --git a/cmd_stream_test.go b/cmd_stream_test.go index dafbcc3..719a28e 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -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, diff --git a/integration/stream_test.go b/integration/stream_test.go index 328f068..6e817a3 100644 --- a/integration/stream_test.go +++ b/integration/stream_test.go @@ -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 @@ -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") }) })