Commit 62f9ac6f authored by antirez's avatar antirez
Browse files

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.
parent 79a1c19a
...@@ -1081,7 +1081,7 @@ invalid: ...@@ -1081,7 +1081,7 @@ invalid:
void xaddCommand(client *c) { void xaddCommand(client *c) {
streamID id; streamID id;
int id_given = 0; /* Was an ID different than "*" specified? */ 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 int approx_maxlen = 0; /* If 1 only delete whole radix tree nodes, so
the maxium length is not applied verbatim. */ the maxium length is not applied verbatim. */
int maxlen_arg_idx = 0; /* Index of the count in MAXLEN, for rewriting. */ int maxlen_arg_idx = 0; /* Index of the count in MAXLEN, for rewriting. */
...@@ -1107,7 +1107,7 @@ void xaddCommand(client *c) { ...@@ -1107,7 +1107,7 @@ void xaddCommand(client *c) {
!= C_OK) return; != C_OK) return;
if (maxlen < 0) { 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; return;
} }
i++; i++;
...@@ -1149,7 +1149,7 @@ void xaddCommand(client *c) { ...@@ -1149,7 +1149,7 @@ void xaddCommand(client *c) {
server.dirty++; server.dirty++;
/* Remove older elements if MAXLEN was specified. */ /* Remove older elements if MAXLEN was specified. */
if (maxlen) { if (maxlen >= 0) {
if (!streamTrimByLength(s,maxlen,approx_maxlen)) { if (!streamTrimByLength(s,maxlen,approx_maxlen)) {
/* If no trimming was performed, for instance because approximated /* If no trimming was performed, for instance because approximated
* trimming length was specified, rewrite the MAXLEN argument * trimming length was specified, rewrite the MAXLEN argument
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment