summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Benoish <guy.benoish@redislabs.com>2019-11-13 16:43:07 +0530
committerantirez <antirez@gmail.com>2019-11-19 17:21:08 +0100
commit08ec8f71ca6b80e2feef3e8fa9e6adec4196f3f5 (patch)
tree7d15af6bda6b2eca9618a4c8e2198849537421f9
parent09e1fe274daf1b597c559f8caf462eaaf4e44106 (diff)
downloadredis-08ec8f71ca6b80e2feef3e8fa9e6adec4196f3f5.tar.gz
XADD with ID 0-0 stores an empty key
Calling XADD with 0-0 or 0 would result in creating an empty key and storing it in the database. Even worse, because XADD will reply with error the action will not be replicated, creating a master-replica inconsistency
-rw-r--r--src/t_stream.c8
-rw-r--r--tests/unit/type/stream.tcl6
2 files changed, 14 insertions, 0 deletions
diff --git a/src/t_stream.c b/src/t_stream.c
index d60cca097..d1095bcc2 100644
--- a/src/t_stream.c
+++ b/src/t_stream.c
@@ -1219,6 +1219,14 @@ void xaddCommand(client *c) {
return;
}
+ /* Return ASAP if minimal ID (0-0) was given so we avoid possibly creating
+ * a new stream and have streamAppendItem fail, leaving an empty key in the
+ * database. */
+ if (id_given && id.ms == 0 && id.seq == 0) {
+ addReplyError(c,"The ID specified in XADD must be greater than 0-0");
+ return;
+ }
+
/* Lookup the stream at key. */
robj *o;
stream *s;
diff --git a/tests/unit/type/stream.tcl b/tests/unit/type/stream.tcl
index c335f7f78..8eaf36b4c 100644
--- a/tests/unit/type/stream.tcl
+++ b/tests/unit/type/stream.tcl
@@ -123,6 +123,12 @@ start_server {
assert {[r xlen mystream] == $j}
}
+ test {XADD with ID 0-0} {
+ r DEL mystream
+ catch {r XADD mystream 0-0 k v} err
+ assert {[r EXISTS mystream] == 0}
+ }
+
test {XRANGE COUNT works as expected} {
assert {[llength [r xrange mystream - + COUNT 10]] == 10}
}