Skip to content

Commit

Permalink
Rename LPOS FIRST option to RANK #1410
Browse files Browse the repository at this point in the history
The FIRST option was renamed in Redis so we're following now.
  • Loading branch information
mp911de committed Sep 15, 2020
1 parent e239641 commit aa02dd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/main/java/io/lettuce/core/LPosArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class LPosArgs implements CompositeArgument {

private Long first;
private Long rank;

private Long maxlen;

Expand Down Expand Up @@ -66,13 +66,13 @@ public static LPosArgs maxlen(long count) {
}

/**
* Creates new {@link LPosArgs} and setting {@literal FIRST}.
* Creates new {@link LPosArgs} and setting {@literal RANK}.
*
* @return new {@link LPosArgs} with {@literal FIRST} set.
* @see LPosArgs#maxlen(long)
* @return new {@link LPosArgs} with {@literal RANK} set.
* @see LPosArgs#rank(long)
*/
public static LPosArgs first(long rank) {
return new LPosArgs().first(rank);
public static LPosArgs rank(long rank) {
return new LPosArgs().rank(rank);
}

}
Expand All @@ -92,14 +92,14 @@ public LPosArgs maxlen(long maxlen) {
}

/**
* Specify the rank of the first element to return, in case there are multiple matches
* Specify the rank of the first element to return, in case there are multiple matches.
*
* @param rank number.
* @return {@code this}
*/
public LPosArgs first(long rank) {
public LPosArgs rank(long rank) {

this.first = rank;
this.rank = rank;
return this;
}

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

if (first != null) {
args.add("FIRST");
args.add(first);
if (rank != null) {
args.add("RANK");
args.add(rank);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

Expand Down Expand Up @@ -125,9 +124,9 @@ void lpos() {

assertThat(redis.lpos(key, "a")).isEqualTo(0);
assertThat(redis.lpos(key, "c")).isEqualTo(2);
assertThat(redis.lpos(key, "c", LPosArgs.Builder.first(1))).isEqualTo(2);
assertThat(redis.lpos(key, "c", LPosArgs.Builder.first(2))).isEqualTo(6);
assertThat(redis.lpos(key, "c", LPosArgs.Builder.first(4))).isNull();
assertThat(redis.lpos(key, "c", LPosArgs.Builder.rank(1))).isEqualTo(2);
assertThat(redis.lpos(key, "c", LPosArgs.Builder.rank(2))).isEqualTo(6);
assertThat(redis.lpos(key, "c", LPosArgs.Builder.rank(4))).isNull();

assertThat(redis.lpos(key, "c", 0)).contains(2L, 6L, 7L);
assertThat(redis.lpos(key, "c", 0, LPosArgs.Builder.maxlen(1))).isEmpty();
Expand Down

0 comments on commit aa02dd0

Please sign in to comment.