Skip to content

Commit

Permalink
Polishing #1502
Browse files Browse the repository at this point in the history
Consistently use lowercase for nomkstream to align with XGroupCreateArgs.

Introduce nomkstream() factory method. Tweak Javadoc, simplify tests.

Original pull request: #1504.
  • Loading branch information
mp911de committed Nov 8, 2020
1 parent 1a1e0be commit 7410f5d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
29 changes: 20 additions & 9 deletions src/main/java/io/lettuce/core/XAddArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class XAddArgs {

private boolean approximateTrimming;

private boolean noMkStream;
private boolean nomkstream;

/**
* Builder entry points for {@link XAddArgs}.
Expand All @@ -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();
}

}

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -147,7 +158,7 @@ public <K, V> void build(CommandArgs<K, V> args) {
args.add(maxlen);
}

if (noMkStream) {
if (nomkstream) {
args.add(CommandKeyword.NOMKSTREAM);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -93,20 +107,12 @@ void xaddMaxLenEfficientTrimming() {
}

@Test
void xaddMaxLenEfficientTrimmingNoMkStream() {
@EnabledOnCommand("LMOVE") // Redis 6.2
void xaddWithNomkstream() {

Map<String, String> 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<StreamMessage<String, String>> messages = redis.xrange(key, Range.unbounded());
assertThat(messages.size()).isEqualTo(1);
assertThat(messages.get(0).getBody()).isEqualTo(body);
}

@Test
Expand Down

0 comments on commit 7410f5d

Please sign in to comment.