diff --git a/src/main/java/io/lettuce/core/XAddArgs.java b/src/main/java/io/lettuce/core/XAddArgs.java index 8fdc78acaa..2c717990e4 100644 --- a/src/main/java/io/lettuce/core/XAddArgs.java +++ b/src/main/java/io/lettuce/core/XAddArgs.java @@ -37,7 +37,7 @@ public class XAddArgs { private boolean approximateTrimming; - private boolean noMkStream; + private boolean nomkstream; /** * Builder entry points for {@link XAddArgs}. @@ -60,6 +60,17 @@ public static XAddArgs maxlen(long count) { return new XAddArgs().maxlen(count); } + /** + * Creates new {@link XAddArgs} and setting {@literal NOMKSTREAM}. + * + * @return new {@link XAddArgs} with {@literal NOMKSTREAM} set. + * @see XAddArgs#nomkstream() + * @since 6.1 + */ + public static XAddArgs nomkstream() { + return new XAddArgs().nomkstream(); + } + } /** @@ -112,25 +123,25 @@ public XAddArgs approximateTrimming(boolean approximateTrimming) { } /** - * Not to create new stream by default. + * Do add the message if the stream does not already exist. * * @return {@code this} * @since 6.1 */ - public XAddArgs noMkStream() { - return noMkStream(true); + public XAddArgs nomkstream() { + return nomkstream(true); } /** - * Not to create new stream by default. + * Do add the message if the stream does not already exist. * - * @param noMkStream {@code true} to apply not to create new stream by default. + * @param nomkstream {@code true} to not create a stream if it does not already exist. * @return {@code this} * @since 6.1 */ - public XAddArgs noMkStream(boolean noMkStream) { + public XAddArgs nomkstream(boolean nomkstream) { - this.noMkStream = noMkStream; + this.nomkstream = nomkstream; return this; } @@ -147,7 +158,7 @@ public void build(CommandArgs args) { args.add(maxlen); } - if (noMkStream) { + if (nomkstream) { args.add(CommandKeyword.NOMKSTREAM); } diff --git a/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java index 1f6e48b6a5..8825058381 100644 --- a/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java @@ -15,11 +15,16 @@ */ package io.lettuce.core.commands; -import static io.lettuce.core.protocol.CommandType.XINFO; -import static org.assertj.core.api.Assertions.assertThat; +import static io.lettuce.core.protocol.CommandType.*; +import static org.assertj.core.api.Assertions.*; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import javax.inject.Inject; @@ -28,7 +33,16 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; -import io.lettuce.core.*; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.TestSupport; +import io.lettuce.core.TransactionResult; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; import io.lettuce.core.XReadArgs.StreamOffset; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; @@ -93,20 +107,12 @@ void xaddMaxLenEfficientTrimming() { } @Test - void xaddMaxLenEfficientTrimmingNoMkStream() { + @EnabledOnCommand("LMOVE") // Redis 6.2 + void xaddWithNomkstream() { - Map body = Collections.singletonMap("foo", "bar"); - String id = redis.xadd(key, XAddArgs.Builder.maxlen(5).approximateTrimming().noMkStream(), body); + String id = redis.xadd(key, XAddArgs.Builder.nomkstream(), Collections.singletonMap("foo", "bar")); assertThat(id).isNull(); assertThat(redis.exists(key)).isEqualTo(0L); - - id = redis.xadd(key, XAddArgs.Builder.maxlen(5).approximateTrimming(), body); - assertThat(id).isNotNull(); - assertThat(redis.exists(key)).isEqualTo(1L); - - List> messages = redis.xrange(key, Range.unbounded()); - assertThat(messages.size()).isEqualTo(1); - assertThat(messages.get(0).getBody()).isEqualTo(body); } @Test