From 7f77fbb87f4bdac3dae72570262925ef981918da Mon Sep 17 00:00:00 2001 From: Harmen Date: Sun, 23 Feb 2020 11:34:02 +0100 Subject: [PATCH] update stream check for redis change --- README.md | 2 +- cmd_stream.go | 2 ++ cmd_stream_test.go | 2 +- db.go | 5 ++++- integration/get_redis.sh | 2 +- redis.go | 1 + stream.go | 1 + 7 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f20a0652..516f651b 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ Commands which will probably not be implemented: ## &c. -Tests are run against Redis 5.0.3. The [./integration](./integration/) subdir +Tests are run against Redis 5.0.7. The [./integration](./integration/) subdir compares miniredis against a real redis instance. If you want to test Redis Sentinel have a look at [minisentinel](https://github.com/Bose/minisentinel). diff --git a/cmd_stream.go b/cmd_stream.go index 87fd7657..af6666df 100644 --- a/cmd_stream.go +++ b/cmd_stream.go @@ -90,6 +90,8 @@ func (m *Miniredis) cmdXadd(c *server.Peer, cmd string, args []string) { switch err { case errInvalidEntryID: c.WriteError(msgInvalidStreamID) + case errZeroStreamValue: + c.WriteError(msgStreamIDZero) case errInvalidStreamValue: c.WriteError(msgStreamIDTooSmall) default: diff --git a/cmd_stream_test.go b/cmd_stream_test.go index 21c3b498..f7de5f4a 100644 --- a/cmd_stream_test.go +++ b/cmd_stream_test.go @@ -43,7 +43,7 @@ func TestStream(t *testing.T) { t.Run("direct usage", func(t *testing.T) { _, err := s.XAdd("s1", "0-0", []string{"name", "foo"}) - mustFail(t, err, errInvalidStreamValue.Error()) + mustFail(t, err, errZeroStreamValue.Error()) id, err := s.XAdd("s1", "12345-67", []string{"name", "bar"}) ok(t, err) diff --git a/db.go b/db.go index ffda6e44..78557e75 100644 --- a/db.go +++ b/db.go @@ -589,7 +589,10 @@ func (db *RedisDB) streamAdd(key, entryID string, values []string) (string, erro if err != nil { return "", err } - if entryID == "0-0" || streamCmp(stream.lastID(), entryID) != -1 { + if entryID == "0-0" { + return "", errZeroStreamValue + } + if streamCmp(stream.lastID(), entryID) != -1 { return "", errInvalidStreamValue } db.streamKeys[key] = append(stream, StreamEntry{ diff --git a/integration/get_redis.sh b/integration/get_redis.sh index 285f6834..f9412d2f 100755 --- a/integration/get_redis.sh +++ b/integration/get_redis.sh @@ -2,7 +2,7 @@ set -eu -VERSION=5.0.5 +VERSION=5.0.7 rm -rf ./redis_src/ mkdir -p ./redis_src/ diff --git a/redis.go b/redis.go index 6fa49411..9e99450f 100644 --- a/redis.go +++ b/redis.go @@ -34,6 +34,7 @@ const ( msgSingleElementPair = "ERR INCR option supports a single increment-element pair" msgInvalidStreamID = "ERR Invalid stream ID specified as stream command argument" msgStreamIDTooSmall = "ERR The ID specified in XADD is equal or smaller than the target stream top item" + msgStreamIDZero = "ERR The ID specified in XADD must be greater than 0-0" msgNoScriptFound = "NOSCRIPT No matching script. Please use EVAL." msgUnsupportedUnit = "ERR unsupported unit provided. please use m, km, ft, mi" msgNotFromScripts = "This Redis command is not allowed from scripts" diff --git a/stream.go b/stream.go index 884bcea3..9e1c0325 100644 --- a/stream.go +++ b/stream.go @@ -13,6 +13,7 @@ import ( var ( errInvalidStreamValue = errors.New("stream id is not bigger than the top item") + errZeroStreamValue = errors.New("stream id is 0-0") ) type streamKey []StreamEntry