From 1ca86f4cbcc78607ba6ec0c4928f6e57d055bd79 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 22 Nov 2022 09:07:46 +0100 Subject: [PATCH] Allow zero maxlen/limit using XTRIM #2250 --- src/main/java/io/lettuce/core/XTrimArgs.java | 4 ++-- .../lettuce/core/commands/StreamCommandIntegrationTests.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/lettuce/core/XTrimArgs.java b/src/main/java/io/lettuce/core/XTrimArgs.java index 65308460d2..2a71b1ecaf 100644 --- a/src/main/java/io/lettuce/core/XTrimArgs.java +++ b/src/main/java/io/lettuce/core/XTrimArgs.java @@ -82,7 +82,7 @@ public static XTrimArgs minId(String minid) { */ public XTrimArgs maxlen(long maxlen) { - LettuceAssert.isTrue(maxlen > 0, "Maxlen must be greater 0"); + LettuceAssert.isTrue(maxlen >= 0, "Maxlen must be greater or equal to 0"); this.maxlen = maxlen; return this; @@ -111,7 +111,7 @@ public XTrimArgs minId(String minid) { */ public XTrimArgs limit(long limit) { - LettuceAssert.isTrue(limit > 0, "Limit must be greater 0"); + LettuceAssert.isTrue(limit >= 0, "Limit must be greater 0"); this.limit = limit; return this; diff --git a/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java index 9334bca6c1..fe2606ced7 100644 --- a/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java @@ -156,6 +156,10 @@ void xtrim() { redis.xtrim(key, true, 8); assertThat(redis.xlen(key)).isLessThanOrEqualTo(10); + + redis.xtrim(key, XTrimArgs.Builder.maxlen(0).limit(0).approximateTrimming()); + + assertThat(redis.xlen(key)).isLessThanOrEqualTo(10); } @Test