From 62f9ac6f436356dc7679d06bedeb98948bcebeb0 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 18 Jun 2018 10:05:18 +0200 Subject: [PATCH] Streams: Change XADD MAXLEN handling of values <= 0. Now a MAXLEN of 0 really does what it means: it will create a zero entries stream. This is useful in order to make sure that the behavior is identical to XTRIM, that must be able to reduce the stream to zero elements when MAXLEN is given. Also now MAXLEN with a count < 0 will return an error. --- src/t_stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 20daeee9..6d8fd92c 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -1081,7 +1081,7 @@ invalid: void xaddCommand(client *c) { streamID id; int id_given = 0; /* Was an ID different than "*" specified? */ - long long maxlen = 0; /* 0 means no maximum length. */ + long long maxlen = -1; /* If left to -1 no trimming is performed. */ int approx_maxlen = 0; /* If 1 only delete whole radix tree nodes, so the maxium length is not applied verbatim. */ int maxlen_arg_idx = 0; /* Index of the count in MAXLEN, for rewriting. */ @@ -1107,7 +1107,7 @@ void xaddCommand(client *c) { != C_OK) return; if (maxlen < 0) { - addReplyError(c,"The MAXLEN argument must be equal or greater than zero. A value of zero means that no trimming should be performed."); + addReplyError(c,"The MAXLEN argument must be >= 0."); return; } i++; @@ -1149,7 +1149,7 @@ void xaddCommand(client *c) { server.dirty++; /* Remove older elements if MAXLEN was specified. */ - if (maxlen) { + if (maxlen >= 0) { if (!streamTrimByLength(s,maxlen,approx_maxlen)) { /* If no trimming was performed, for instance because approximated * trimming length was specified, rewrite the MAXLEN argument