Skip to content

Commit

Permalink
Merge pull request #137 from alicebob/upstream
Browse files Browse the repository at this point in the history
update stream check for redis change
  • Loading branch information
alicebob authored Feb 23, 2020
2 parents 15932cc + 7f77fbb commit 3f1597e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions cmd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion integration/get_redis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

VERSION=5.0.5
VERSION=5.0.7

rm -rf ./redis_src/
mkdir -p ./redis_src/
Expand Down
1 change: 1 addition & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f1597e

Please sign in to comment.