diff --git a/java/client/src/main/java/glide/api/models/commands/stream/StreamGroupOptions.java b/java/client/src/main/java/glide/api/models/commands/stream/StreamGroupOptions.java index f1cceeed1e..1ed8996907 100644 --- a/java/client/src/main/java/glide/api/models/commands/stream/StreamGroupOptions.java +++ b/java/client/src/main/java/glide/api/models/commands/stream/StreamGroupOptions.java @@ -4,6 +4,7 @@ import glide.api.commands.StreamBaseCommands; import java.util.ArrayList; import java.util.List; +import lombok.Builder; /** * Optional arguments for {@link StreamBaseCommands#xgroupCreate(String, String, String, @@ -11,60 +12,37 @@ * * @see valkey.io */ +@Builder public final class StreamGroupOptions { + // Redis API String argument for makeStream public static final String MAKE_STREAM_REDIS_API = "MKSTREAM"; - public static final String ENTRIES_READ_REDIS_API = "ENTRIESREAD"; - /** If the stream doesn't exist, creates a new stream with a length of 0. */ - boolean makeStream; + // Redis API String argument for entriesRead + public static final String ENTRIES_READ_REDIS_API = "ENTRIESREAD"; /** - * An arbitrary ID (that isn't the first ID, last ID, or the zero "0-0". Use it to - * find out how many entries are between the arbitrary ID (excluding it) and the stream's last - * entry. - * - * @since Redis 7.0.0 + * If true and the stream doesn't exist, creates a new stream with a length of + * 0. */ - String entriesRead; + @Builder.Default private boolean mkStream = false; - /** - * Options for {@link StreamBaseCommands#xgroupCreate(String, String, String, StreamGroupOptions)} - * - * @param makeStream If the stream doesn't exist, creates a new stream with a length of 0 - * . - */ - public StreamGroupOptions(Boolean makeStream) { - this.makeStream = makeStream; - } + public static class StreamGroupOptionsBuilder { - /** - * Options for {@link StreamBaseCommands#xgroupCreate(String, String, String, StreamGroupOptions)} - * - * @param entriesRead An arbitrary ID that isn't the first ID, last ID, or the zero "0-0" - * . Use it to find out how many entries are between the arbitrary ID (excluding it) - * and the stream's last entry. - * @since ENTRIESREAD was added in Redis 7.0.0. - */ - public StreamGroupOptions(String entriesRead) { - this.makeStream = false; - this.entriesRead = entriesRead; + /** If the stream doesn't exist, this creates a new stream with a length of 0. */ + public StreamGroupOptionsBuilder makeStream() { + return mkStream(true); + } } /** - * Options for {@link StreamBaseCommands#xgroupCreate(String, String, String, StreamGroupOptions)} + * An arbitrary ID (that isn't the first ID, last ID, or the zero "0-0". Use it to + * find out how many entries are between the arbitrary ID (excluding it) and the stream's last + * entry. * - * @param makeStream If the stream doesn't exist, creates a new stream with a length of 0 - * . - * @param entriesRead An arbitrary ID that isn't the first ID, last ID, or the zero "0-0" - * . Use it to find out how many entries are between the arbitrary ID (excluding it) - * and the stream's last entry. - * @since ENTRIESREAD was added in Redis 7.0.0. + * @since Redis 7.0.0 */ - public StreamGroupOptions(Boolean makeStream, String entriesRead) { - this.makeStream = makeStream; - this.entriesRead = entriesRead; - } + private String entriesRead; /** * Converts options and the key-to-id input for {@link StreamBaseCommands#xgroupCreate(String, @@ -75,7 +53,7 @@ public StreamGroupOptions(Boolean makeStream, String entriesRead) { public String[] toArgs() { List optionArgs = new ArrayList<>(); - if (this.makeStream) { + if (this.mkStream) { optionArgs.add(MAKE_STREAM_REDIS_API); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index bc487c2ec0..dbab49630d 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -4308,7 +4308,8 @@ public void xgroupCreate_withOptions() { String groupName = "testGroupName"; String id = "testId"; String testEntry = "testEntry"; - StreamGroupOptions options = new StreamGroupOptions(true, testEntry); + StreamGroupOptions options = + StreamGroupOptions.builder().makeStream().entriesRead(testEntry).build(); String[] arguments = new String[] {key, groupName, id, MAKE_STREAM_REDIS_API, ENTRIES_READ_REDIS_API, testEntry}; diff --git a/java/client/src/test/java/glide/api/models/TransactionTests.java b/java/client/src/test/java/glide/api/models/TransactionTests.java index 20924b671d..37bef17148 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -744,7 +744,11 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)), transaction.xgroupCreate("key", "group", "id"); results.add(Pair.of(XGroupCreate, buildArgs("key", "group", "id"))); - transaction.xgroupCreate("key", "group", "id", new StreamGroupOptions(true, "entry")); + transaction.xgroupCreate( + "key", + "group", + "id", + StreamGroupOptions.builder().makeStream().entriesRead("entry").build()); results.add( Pair.of( XGroupCreate, diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index fa70bd6cea..d86990e711 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -3341,7 +3341,8 @@ public void xgroupCreate_xgroupDestroy(BaseClient client) { // Stream with option to create creates stream & Group assertEquals( - OK, client.xgroupCreate(key, groupName, streamId, new StreamGroupOptions(true)).get()); + OK, client.xgroupCreate(key, groupName, streamId, StreamGroupOptions.builder().makeStream() + .build()).get()); // ...and again results in BUSYGROUP error, because group names must be unique executionException = @@ -3357,7 +3358,7 @@ public void xgroupCreate_xgroupDestroy(BaseClient client) { assertEquals(false, client.xgroupDestroy(key, groupName).get()); // ENTRIESREAD option was added in redis 7.0.0 - StreamGroupOptions entriesReadOption = new StreamGroupOptions("10"); + StreamGroupOptions entriesReadOption = StreamGroupOptions.builder().entriesRead("10").build(); if (REDIS_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertEquals(OK, client.xgroupCreate(key, groupName, streamId, entriesReadOption).get()); } else { @@ -3375,7 +3376,7 @@ public void xgroupCreate_xgroupDestroy(BaseClient client) { ExecutionException.class, () -> client - .xgroupCreate(stringKey, groupName, streamId, new StreamGroupOptions(true)) + .xgroupCreate(stringKey, groupName, streamId, StreamGroupOptions.builder().makeStream().build()) .get()); assertInstanceOf(RequestException.class, executionException.getCause()); diff --git a/java/integTest/src/test/java/glide/TransactionTestUtilities.java b/java/integTest/src/test/java/glide/TransactionTestUtilities.java index ba905d0fc6..be6bb9035b 100644 --- a/java/integTest/src/test/java/glide/TransactionTestUtilities.java +++ b/java/integTest/src/test/java/glide/TransactionTestUtilities.java @@ -687,7 +687,7 @@ private static Object[] streamCommands(BaseTransaction transaction) { .xrevrange(streamKey1, IdBound.of("0-1"), IdBound.of("0-1"), 1L) .xtrim(streamKey1, new MinId(true, "0-2")) .xgroupCreate(streamKey1, groupName1, "0-0") - .xgroupCreate(streamKey1, groupName2, "0-0", new StreamGroupOptions(true)) + .xgroupCreate(streamKey1, groupName2, "0-0", StreamGroupOptions.builder().makeStream().build()) .xgroupDestroy(streamKey1, groupName1) .xgroupDestroy(streamKey1, groupName2) .xdel(streamKey1, new String[] {"0-3", "0-5"});