
redis.clients.jedis.params.ScanParams Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis Show documentation
Show all versions of jedis Show documentation
Jedis is a blazingly small and sane Redis java client.
package redis.clients.jedis.params;
import static redis.clients.jedis.Protocol.Keyword.MATCH;
import java.nio.ByteBuffer;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.util.SafeEncoder;
public class ScanParams implements IParams {
private final Map params = new EnumMap<>(Keyword.class);
public static final String SCAN_POINTER_START = String.valueOf(0);
public static final byte[] SCAN_POINTER_START_BINARY = SafeEncoder.encode(SCAN_POINTER_START);
public ScanParams match(final byte[] pattern) {
params.put(MATCH, ByteBuffer.wrap(pattern));
return this;
}
/**
* @see MATCH option in Redis documentation
*/
public ScanParams match(final String pattern) {
params.put(MATCH, ByteBuffer.wrap(SafeEncoder.encode(pattern)));
return this;
}
/**
* @see COUNT option in Redis documentation
*/
public ScanParams count(final Integer count) {
params.put(Keyword.COUNT, ByteBuffer.wrap(Protocol.toByteArray(count)));
return this;
}
@Override
public void addParams(CommandArguments args) {
for (Map.Entry param : params.entrySet()) {
args.add(param.getKey());
args.add(param.getValue().array());
}
}
public byte[] binaryMatch() {
if (params.containsKey(MATCH)) {
return params.get(MATCH).array();
} else {
return null;
}
}
public String match() {
if (params.containsKey(MATCH)) {
return new String(params.get(MATCH).array());
} else {
return null;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ScanParams that = (ScanParams) o;
return Objects.equals(params, that.params);
}
@Override
public int hashCode() {
return Objects.hash(params);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy