Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Mar 22, 2024
1 parent 46f1613 commit 4e0483a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public CompletableFuture<Long> zcard(@NonNull String key) {
}

@Override
public CompletableFuture<String> xadd(@NonNull String key, Map<String, String> values) {
public CompletableFuture<String> xadd(@NonNull String key, @NonNull Map<String, String> values) {
return xadd(key, values, StreamAddOptions.builder().build());
}

Expand All @@ -603,7 +603,7 @@ public CompletableFuture<String> xadd(
String[] arguments =
ArrayUtils.addAll(
ArrayUtils.addFirst(options.toArgs(), key),
ArrayTransformUtils.convertMapToKeyValueStringArray(values));
convertMapToKeyValueStringArray(values));
return commandManager.submitNewCommand(XAdd, arguments, this::handleStringOrNullResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface StreamBaseCommands {
* set to <code>false</code> and no stream with the matching <code>key</code> exists.
* @example
* <pre>{@code
* // Stream options to not make the stream if "key" is not a stream, as use stream id of "sid"
* // Option to use the existing stream, or return null if the stream doesn't already exist at "key"
* StreamAddOptions options = StreamAddOptions.builder().id("sid").makeStream(Boolean.FALSE).build();
* String streamId = client.xadd("key", Map.of("name", "Sara", "surname", "OConnor"), options).get();
* if (streamId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,9 @@ public T zcard(@NonNull String key) {
* @param values field-value pairs to be added to the entry.
* @return Command Response - The id of the added entry.
*/
public T xadd(String key, Map<String, String> values) {
return this.xadd(key, values, StreamAddOptions.builder().build());
public T xadd(@NonNull String key, @NonNull Map<String, String> values) {
this.xadd(key, values, StreamAddOptions.builder().build());
return getThis();
}

/**
Expand All @@ -1267,11 +1268,11 @@ public T xadd(String key, Map<String, String> values) {
* options.makeStream</code> is set to <code>false</code> and no stream with the matching
* <code>key</code> exists.
*/
public T xadd(String key, Map<String, String> values, StreamAddOptions options) {
public T xadd(@NonNull String key, @NonNull Map<String, String> values, @NonNull StreamAddOptions options) {
String[] arguments =
ArrayUtils.addAll(
ArrayUtils.addFirst(options.toArgs(), key),
ArrayTransformUtils.convertMapToKeyValueStringArray(values));
convertMapToKeyValueStringArray(values));
ArgsArray commandArgs = buildArgs(arguments);
protobufTransaction.addCommands(buildCommand(XAdd, commandArgs));
return getThis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;

/**
* Optional arguments to {@link StreamBaseCommands#xadd}
Expand Down Expand Up @@ -37,8 +38,8 @@ public final class StreamAddOptions {

public abstract static class StreamTrimOptions {
/**
* If `true`, the stream will be trimmed exactly. Equivalent to `=` in the Redis API. Otherwise
* the stream will be trimmed in a near-exact manner, which is more efficient, equivalent to `~`
* If <code>true</code>, the stream will be trimmed exactly. Equivalent to <code>=</code> in the Redis API. Otherwise,
* the stream will be trimmed in a near-exact manner, which is more efficient, equivalent to <code>~</code>
* in the Redis API.
*/
protected Boolean exact;
Expand Down Expand Up @@ -70,12 +71,12 @@ public static class MinId extends StreamTrimOptions {
/** Trim the stream according to entry ID. Equivalent to <code>MINID</code> in the Redis API. */
private final String threshold;

public MinId(Boolean exact, String threshold) {
public MinId(boolean exact, @NonNull String threshold) {
this.threshold = threshold;
this.exact = exact;
}

public MinId(Boolean exact, String threshold, Long limit) {
public MinId(boolean exact, @NonNull String threshold, long limit) {
this.threshold = threshold;
this.exact = exact;
this.limit = limit;
Expand All @@ -97,12 +98,12 @@ public static class Maxlen extends StreamTrimOptions {
*/
private final Long threshold;

public Maxlen(Boolean exact, Long threshold) {
public Maxlen(boolean exact, long threshold) {
this.threshold = threshold;
this.exact = exact;
}

public Maxlen(Boolean exact, Long threshold, Long limit) {
public Maxlen(boolean exact, long threshold, long limit) {
this.threshold = threshold;
this.exact = exact;
this.limit = limit;
Expand Down
11 changes: 11 additions & 0 deletions java/client/src/test/java/glide/api/models/TransactionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ public void transaction_builds_protobuf_request(BaseTransaction<?> transaction)
transaction.zcard("key");
results.add(Pair.of(Zcard, ArgsArray.newBuilder().addArgs("key").build()));

transaction.xadd("key", Map.of("field1", "foo1"));
results.add(
Pair.of(
XAdd,
ArgsArray.newBuilder()
.addArgs("key")
.addArgs("*")
.addArgs("field1")
.addArgs("foo1")
.build()));

transaction.xadd("key", Map.of("field1", "foo1"), StreamAddOptions.builder().id("id").build());
results.add(
Pair.of(
Expand Down

0 comments on commit 4e0483a

Please sign in to comment.