Skip to content

Commit

Permalink
Update StreamAddOptions for 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 25, 2024
1 parent edf08d9 commit dfb18e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface StreamBaseCommands {
*
* @see <a href="https://redis.io/commands/xadd/">redis.io</a> for details.
* @param key The key of the stream.
* @param values field-value pairs to be added to the entry.
* @param values Field-value pairs to be added to the entry.
* @return The id of the added entry.
* @example
* <pre>{@code
Expand All @@ -33,10 +33,10 @@ public interface StreamBaseCommands {
*
* @see <a href="https://redis.io/commands/xadd/">redis.io</a> for details.
* @param key The key of the stream.
* @param values field-value pairs to be added to the entry.
* @param values Field-value pairs to be added to the entry.
* @param options Stream add options.
* @return The id of the added entry, or <code>null</code> if <code>options.makeStream</code> is
* set to <code>false</code> and no stream with the matching <code>key</code> exists.
* @return The id of the added entry, or <code>null</code> if {@link StreamAddOptions#makeStream}
* is set to <code>false</code> and no stream with the matching <code>key</code> exists.
* @example
* <pre>{@code
* // Option to use the existing stream, or return null if the stream doesn't already exist at "key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ public T zcard(@NonNull String key) {
*
* @see <a href="https://redis.io/commands/xadd/">redis.io</a> for details.
* @param key The key of the stream.
* @param values field-value pairs to be added to the entry.
* @param values Field-value pairs to be added to the entry.
* @return Command Response - The id of the added entry.
*/
public T xadd(@NonNull String key, @NonNull Map<String, String> values) {
Expand All @@ -1261,10 +1261,10 @@ public T xadd(@NonNull String key, @NonNull Map<String, String> values) {
*
* @see <a href="https://redis.io/commands/xadd/">redis.io</a> for details.
* @param key The key of the stream.
* @param values field-value pairs to be added to the entry.
* @param values Field-value pairs to be added to the entry.
* @param options Stream add options.
* @return Command Response - The id of the added entry, or <code>null</code> if <code>
* options.makeStream</code> is set to <code>false</code> and no stream with the matching
* @return Command Response - The id of the added entry, or <code>null</code> if {@link
* StreamAddOptions#makeStream} is set to <code>false</code> and no stream with the matching
* <code>key</code> exists.
*/
public T xadd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract static class StreamTrimOptions {
* 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;
protected boolean exact;

/** If set, sets the maximal amount of entries that will be deleted. */
protected Long limit;
Expand Down Expand Up @@ -71,49 +71,79 @@ 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;

/**
* Create a trim option to trim stream based on stream ID.
*
* @param exact whether to match exactly on the threshold.
* @param threshold comparison id.
*/
public MinId(boolean exact, @NonNull String threshold) {
this.threshold = threshold;
this.exact = exact;
}

/**
* Create a trim option to trim stream based on stream ID.
*
* @param exact whether to match exactly on the threshold.
* @param threshold comparison id.
* @param limit max number of stream entries to be trimmed.
*/
public MinId(boolean exact, @NonNull String threshold, long limit) {
this.threshold = threshold;
this.exact = exact;
this.limit = limit;
}

public String getMethod() {
@Override
protected String getMethod() {
return TRIM_MINID_REDIS_API;
}

public String getThreshold() {
@Override
protected String getThreshold() {
return threshold;
}
}

public static class Maxlen extends StreamTrimOptions {
public static class MaxLen extends StreamTrimOptions {
/**
* Trim the stream according to length. <br>
* Trim the stream according to length.<br>
* Equivalent to <code>MAXLEN</code> in the Redis API.
*/
private final Long threshold;

public Maxlen(boolean exact, long threshold) {
/**
* Create a Max Length trim option to trim stream based on length.
*
* @param exact whether to match exactly on the threshold.
* @param threshold comparison count.
*/
public MaxLen(boolean exact, long threshold) {
this.threshold = threshold;
this.exact = exact;
}

public Maxlen(boolean exact, long threshold, long limit) {
/**
* Create a Max Length trim option to trim stream entries exceeds the threshold.
*
* @param exact whether to match exactly on the threshold.
* @param threshold comparison count.
* @param limit max number of stream entries to be trimmed.
*/
public MaxLen(boolean exact, long threshold, long limit) {
this.threshold = threshold;
this.exact = exact;
this.limit = limit;
}

public String getMethod() {
@Override
protected String getMethod() {
return TRIM_MAXLEN_REDIS_API;
}

public String getThreshold() {
@Override
protected String getThreshold() {
return threshold.toString();
}
}
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ private static List<Arguments> getStreamAddOptions() {
StreamAddOptions.builder()
.id("id")
.makeStream(Boolean.TRUE)
.trim(new StreamAddOptions.Maxlen(Boolean.TRUE, 5L, 10L))
.trim(new StreamAddOptions.MaxLen(Boolean.TRUE, 5L, 10L))
.build(),
new String[] {
"testKey",
Expand All @@ -1707,7 +1707,7 @@ private static List<Arguments> getStreamAddOptions() {
// MAXLEN with non exact match
StreamAddOptions.builder()
.makeStream(Boolean.FALSE)
.trim(new StreamAddOptions.Maxlen(Boolean.FALSE, 2L))
.trim(new StreamAddOptions.MaxLen(Boolean.FALSE, 2L))
.build(),
new String[] {
"testKey",
Expand Down
2 changes: 1 addition & 1 deletion java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ public void xadd(BaseClient client) {
key,
Map.of(field1, "foo3", field2, "bar3"),
StreamAddOptions.builder()
.trim(new StreamAddOptions.Maxlen(Boolean.TRUE, 2L))
.trim(new StreamAddOptions.MaxLen(Boolean.TRUE, 2L))
.build())
.get();
assertNotNull(id);
Expand Down

0 comments on commit dfb18e3

Please sign in to comment.