
io.lettuce.core.LPosArgs Maven / Gradle / Ivy
Show all versions of lettuce-core Show documentation
package io.lettuce.core;
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;
/**
* Argument list builder for the Redis LPOS command. Static import the methods from
* {@link Builder} and call the methods: {@code maxlen(…)} .
*
* {@link LPosArgs} is a mutable object and instances should be used only once to avoid shared mutable state.
*
* @author Mark Paluch
* @since 5.3.2
*/
public class LPosArgs implements CompositeArgument {
private Long rank;
private Long maxlen;
/**
* Builder entry points for {@link LPosArgs}.
*/
public static class Builder {
/**
* Utility constructor.
*/
private Builder() {
}
/**
* Creates new empty {@link LPosArgs}.
*
* @return new {@link LPosArgs}.
* @see LPosArgs#maxlen(long)
*/
public static LPosArgs empty() {
return new LPosArgs();
}
/**
* Creates new {@link LPosArgs} and setting {@literal MAXLEN}.
*
* @return new {@link LPosArgs} with {@literal MAXLEN} set.
* @see LPosArgs#maxlen(long)
*/
public static LPosArgs maxlen(long count) {
return new LPosArgs().maxlen(count);
}
/**
* Creates new {@link LPosArgs} and setting {@literal RANK}.
*
* @return new {@link LPosArgs} with {@literal RANK} set.
* @see LPosArgs#rank(long)
*/
public static LPosArgs rank(long rank) {
return new LPosArgs().rank(rank);
}
}
/**
* Limit list scanning to {@code maxlen} entries.
*
* @param maxlen number greater 0.
* @return {@code this}
*/
public LPosArgs maxlen(long maxlen) {
LettuceAssert.isTrue(maxlen > 0, "Maxlen must be greater 0");
this.maxlen = maxlen;
return this;
}
/**
* Specify the rank of the first element to return, in case there are multiple matches.
*
* @param rank number.
* @return {@code this}
*/
public LPosArgs rank(long rank) {
this.rank = rank;
return this;
}
@Override
public void build(CommandArgs args) {
if (maxlen != null) {
args.add(CommandKeyword.MAXLEN);
args.add(maxlen);
}
if (rank != null) {
args.add("RANK");
args.add(rank);
}
}
}