From e5f58c0c6a77c204f8b6e10bfd8683f656cf2945 Mon Sep 17 00:00:00 2001 From: Joakim Hamren Date: Fri, 10 May 2024 21:49:26 +0200 Subject: [PATCH 1/4] Support for the NOMKSTREAM option for XADD --- cmd_stream.go | 10 +++++++++- cmd_stream_test.go | 7 +++++++ integration/stream_test.go | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd_stream.go b/cmd_stream.go index 5cd8c261..b6d00343 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 dafbcc32..27a19a9b 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -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, diff --git a/integration/stream_test.go b/integration/stream_test.go index 328f0684..e8a2a63a 100644 --- a/integration/stream_test.go +++ b/integration/stream_test.go @@ -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 @@ -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") }) }) From 1e417579d16d15d6d1f2de32c09cb653413103cb Mon Sep 17 00:00:00 2001 From: Joakim Hamren Date: Fri, 10 May 2024 22:20:26 +0200 Subject: [PATCH 2/4] few more test cases --- cmd_stream_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd_stream_test.go b/cmd_stream_test.go index 27a19a9b..649fad52 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -188,10 +188,22 @@ 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, ) + mustDo(t, c, + "XADD", "reallynosuchkey", "NOMKSTREAM", "MAXLEN", "~", "10", "MINID", "1672545848004-0", "*", "one", "1", + proto.Nil, + ) }) t.Run("error cases", func(t *testing.T) { From 237ef145dfb5dd5288829211984d82d9c6b774c9 Mon Sep 17 00:00:00 2001 From: Joakim Hamren Date: Fri, 10 May 2024 22:27:01 +0200 Subject: [PATCH 3/4] but skip the invalid one --- cmd_stream_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmd_stream_test.go b/cmd_stream_test.go index 649fad52..719a28eb 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -200,10 +200,6 @@ func TestStreamAdd(t *testing.T) { "XADD", "reallynosuchkey", "NOMKSTREAM", "MAXLEN", "~", "10", "*", "one", "1", proto.Nil, ) - mustDo(t, c, - "XADD", "reallynosuchkey", "NOMKSTREAM", "MAXLEN", "~", "10", "MINID", "1672545848004-0", "*", "one", "1", - proto.Nil, - ) }) t.Run("error cases", func(t *testing.T) { From 73e4e1769cd675b62455738a113c15e66951b91f Mon Sep 17 00:00:00 2001 From: Joakim Hamren Date: Fri, 10 May 2024 22:29:51 +0200 Subject: [PATCH 4/4] use the option --- integration/stream_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/stream_test.go b/integration/stream_test.go index e8a2a63a..6e817a3d 100644 --- a/integration/stream_test.go +++ b/integration/stream_test.go @@ -27,6 +27,7 @@ func TestStream(t *testing.T) { ) c.Do("XADD", "reallynosuchkey", + "NOMKSTREAM", "*", "name", "Earth", ) @@ -132,7 +133,7 @@ func TestStream(t *testing.T) { c.Do("EXEC") c.Do("MULTI") - c.Do("XADD", "reallynosuchkey", "MAXLEN", "four", "*", "name", "Mercury") + c.Do("XADD", "reallynosuchkey", "NOMKSTREAM", "MAXLEN", "four", "*", "name", "Mercury") c.Do("EXEC") }) })