Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/jedis5-breaking.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
- `BYTE_ARRAY_LIST` (use `BINARY_LIST`)
- `BINARY_MAP_FROM_PAIRS`

- `Params` abstract class is removed.
- `toString()` support used by its sub-classes is now unavailable.

- `CommandListFilterByParams` now throws `IllegalArgumentException` (instead of `JedisDataException`) in case of unfulfilling filter.

- `FailoverParams` now throws `IllegalArgumentException` (instead of `IllegalStateException`) in case of unfulfilling optional arguments.

- `XPendingParams` now throws `IllegalArgumentException` (instead of `IllegalStateException`) in case of unfulfilling optional arguments.

- `getParams()` method is removed from `SortingParams` class.

<!--- Deprecated in Jedis 4 --->

- `quit()` method has been removed from `Connection` and `ServerCommands` interface and implementations.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public final CommandObject<Long> exists(byte[]... keys) {
}

public final CommandObject<Long> persist(String key) {
return new CommandObject<>(commandArguments(PERSIST).key(key), BuilderFactory.LONG);
return new CommandObject<>(commandArguments(Command.PERSIST).key(key), BuilderFactory.LONG);
}

public final CommandObject<Long> persist(byte[] key) {
return new CommandObject<>(commandArguments(PERSIST).key(key), BuilderFactory.LONG);
return new CommandObject<>(commandArguments(Command.PERSIST).key(key), BuilderFactory.LONG);
}

public final CommandObject<String> type(String key) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4172,7 +4172,7 @@ public String clientKill(final String ip, final int port) {
@Override
public long clientKill(ClientKillParams params) {
checkIsInMultiOrPipeline();
connection.sendCommand(CLIENT, joinParameters(KILL.getRaw(), params.getByteParams()));
connection.sendCommand(new CommandArguments(CLIENT).add(KILL).addParams(params));
return this.connection.getIntegerReply();
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,16 @@ public static enum Keyword implements Rawable {

AGGREGATE, ALPHA, BY, GET, LIMIT, NO, NOSORT, ONE, SET, STORE, WEIGHTS, WITHSCORE, WITHSCORES,
RESETSTAT, REWRITE, RESET, FLUSH, EXISTS, LOAD, LEN, HELP, SCHEDULE, MATCH, COUNT, TYPE, KEYS,
REFCOUNT, ENCODING, IDLETIME, FREQ, REPLACE, GETNAME, SETNAME, SETINFO, LIST, ID, KILL,
REFCOUNT, ENCODING, IDLETIME, FREQ, REPLACE, GETNAME, SETNAME, SETINFO, LIST, ID, KILL, PERSIST,
STREAMS, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, IDLE, TIME, BLOCK, NOACK,
RETRYCOUNT, STREAM, GROUPS, CONSUMERS, JUSTID, WITHVALUES, NOMKSTREAM, MINID, CREATECONSUMER,
SETUSER, GETUSER, DELUSER, WHOAMI, USERS, CAT, GENPASS, LOG, SAVE, DRYRUN, COPY, AUTH, AUTH2,
NX, XX, EX, PX, EXAT, PXAT, CH, ABSTTL, KEEPTTL, INCR, INFO, NOW, PAUSE, UNPAUSE, UNBLOCK, REV,
WITHCOORD, WITHDIST, WITHHASH, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE,
NX, XX, EX, PX, EXAT, PXAT, ABSTTL, KEEPTTL, INCR, LT, GT, CH, INFO, PAUSE, UNPAUSE, UNBLOCK,
REV, WITHCOORD, WITHDIST, WITHHASH, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE,
STOREDIST, TO, FORCE, TIMEOUT, DB, UNLOAD, ABORT, IDX, MINMATCHLEN, WITHMATCHLEN, FULL,
DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, GETKEYS, GETKEYSANDFLAGS, DOCS, FILTERBY, DUMP,
MODULE, ACLCAT, PATTERN, DOCTOR, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS,
MODULE, ACLCAT, PATTERN, DOCTOR, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS, RANK,
NOW, VERSION, ADDR, SKIPME, USER, LADDR,
CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB;

private final byte[] raw;
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/redis/clients/jedis/args/RawableFactory.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package redis.clients.jedis.args;

import static redis.clients.jedis.Protocol.toByteArray;
import static redis.clients.jedis.util.SafeEncoder.encode;

import java.util.Arrays;
import redis.clients.jedis.util.SafeEncoder;

/**
* Factory class to get {@link Rawable} objects.
Expand Down Expand Up @@ -52,7 +54,7 @@ public static class Raw implements Rawable {
private final byte[] raw;

public Raw(byte[] raw) {
this.raw = raw;
this.raw = Arrays.copyOf(raw, raw.length);
}

@Override
Expand All @@ -64,10 +66,17 @@ public byte[] getRaw() {
/**
* A {@link Rawable} wrapping a {@link String}.
*/
public static class RawString extends Raw {
public static class RawString implements Rawable {

private final byte[] raw;

public RawString(String str) {
super(encode(str));
this.raw = SafeEncoder.encode(str);
}

@Override
public byte[] getRaw() {
return raw;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/params/BitPosParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ public BitPosParams start(long start) {
return this;
}

/**
* {@link BitPosParams#start(long) START} must be set for END option.
*/
public BitPosParams end(long end) {
this.end = end;
return this;
}

/**
* Both {@link BitPosParams#start(long) START} and {@link BitPosParams#end(long) END} both must be
* set for MODIFIER option.
*/
public BitPosParams modifier(BitCountOption modifier) {
this.modifier = modifier;
return this;
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/redis/clients/jedis/params/ClientKillParams.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
package redis.clients.jedis.params;

import redis.clients.jedis.args.ClientType;
import java.util.ArrayList;

public class ClientKillParams extends Params {
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.args.ClientType;
import redis.clients.jedis.util.KeyValue;

private static final String ID = "ID";
private static final String TYPE = "TYPE";
private static final String ADDR = "ADDR";
private static final String SKIPME = "SKIPME";
private static final String USER = "USER";
private static final String LADDR = "LADDR";
public class ClientKillParams implements IParams {

public static enum SkipMe {
YES, NO;
}

private final ArrayList<KeyValue<Keyword, Object>> params = new ArrayList<>();

public ClientKillParams() {
}

public static ClientKillParams clientKillParams() {
return new ClientKillParams();
}

public ClientKillParams id(String clientId) {
addParam(ID, clientId);
private ClientKillParams addParam(Keyword key, Object value) {
params.add(KeyValue.of(key, value));
return this;
}

public ClientKillParams id(String clientId) {
return addParam(Keyword.ID, clientId);
}

public ClientKillParams id(byte[] clientId) {
addParam(ID, clientId);
return this;
return addParam(Keyword.ID, clientId);
}

public ClientKillParams type(ClientType type) {
addParam(TYPE, type);
return this;
return addParam(Keyword.TYPE, type);
}

public ClientKillParams addr(String ipPort) {
addParam(ADDR, ipPort);
return this;
return addParam(Keyword.ADDR, ipPort);
}

public ClientKillParams addr(byte[] ipPort) {
addParam(ADDR, ipPort);
return this;
return addParam(Keyword.ADDR, ipPort);
}

public ClientKillParams addr(String ip, int port) {
addParam(ADDR, ip + ':' + port);
return this;
return addParam(Keyword.ADDR, ip + ':' + port);
}

public ClientKillParams skipMe(SkipMe skipMe) {
addParam(SKIPME, skipMe);
return this;
return addParam(Keyword.SKIPME, skipMe);
}

public ClientKillParams user(String username) {
addParam(USER, username);
return this;
return addParam(Keyword.USER, username);
}

public ClientKillParams laddr(String ipPort) {
addParam(LADDR, ipPort);
return this;
return addParam(Keyword.LADDR, ipPort);
}

public ClientKillParams laddr(String ip, int port) {
addParam(LADDR, ip + ':' + port);
return this;
return addParam(Keyword.LADDR, ip + ':' + port);
}

@Override
public void addParams(CommandArguments args) {
params.forEach(kv -> args.add(kv.getKey()).add(kv.getValue()));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package redis.clients.jedis.params;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.exceptions.JedisDataException;

import static redis.clients.jedis.Protocol.Keyword.FILTERBY;
import static redis.clients.jedis.Protocol.Keyword.MODULE;
import static redis.clients.jedis.Protocol.Keyword.ACLCAT;
import static redis.clients.jedis.Protocol.Keyword.PATTERN;
import redis.clients.jedis.Protocol.Keyword;

public class CommandListFilterByParams implements IParams {

private String moduleName;
private String category;
private String pattern;
Expand All @@ -34,19 +30,20 @@ public CommandListFilterByParams filterByPattern(String pattern) {

@Override
public void addParams(CommandArguments args) {
args.add(FILTERBY);
args.add(Keyword.FILTERBY);

if (moduleName != null && category == null && pattern == null) {
args.add(MODULE);
args.add(Keyword.MODULE);
args.add(moduleName);
} else if (moduleName == null && category != null && pattern == null) {
args.add(ACLCAT);
args.add(Keyword.ACLCAT);
args.add(category);
} else if (moduleName == null && category == null && pattern != null) {
args.add(PATTERN);
args.add(Keyword.PATTERN);
args.add(pattern);
} else {
throw new JedisDataException("Must choose exactly one filter");
throw new IllegalArgumentException("Must choose exactly one filter in "
+ getClass().getSimpleName());
}
}
}
19 changes: 8 additions & 11 deletions src/main/java/redis/clients/jedis/params/FailoverParams.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package redis.clients.jedis.params;

import static redis.clients.jedis.Protocol.Keyword.FORCE;
import static redis.clients.jedis.Protocol.Keyword.TIMEOUT;
import static redis.clients.jedis.Protocol.Keyword.TO;
import static redis.clients.jedis.Protocol.toByteArray;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Protocol.Keyword;

public class FailoverParams implements IParams {

Expand All @@ -30,7 +26,9 @@ public FailoverParams to(HostAndPort to) {
}

/**
* WARNING: FORCE option can be used only if both TO and TIMEOUT options are specified.
* Both TO ({@link FailoverParams#to(redis.clients.jedis.HostAndPort)} or
* {@link FailoverParams#to(java.lang.String, int)}) and
* {@link FailoverParams#timeout(long) TIMEOUT} must be set in order for FORCE option.
*/
public FailoverParams force() {
this.force = true;
Expand All @@ -46,19 +44,18 @@ public FailoverParams timeout(long timeout) {
public void addParams(CommandArguments args) {

if (to != null) {
args.add(TO);
args.add(to.getHost()).add(toByteArray(to.getPort()));
args.add(Keyword.TO).add(to.getHost()).add(to.getPort());
}

if (force) {
if (to == null || timeout == null) {
throw new IllegalStateException("ERR FAILOVER with force option requires both a timeout and target HOST and IP.");
throw new IllegalArgumentException("FAILOVER with force option requires both a timeout and target HOST and IP.");
}
args.add(FORCE);
args.add(Keyword.FORCE);
}

if (timeout != null) {
args.add(TIMEOUT).add(toByteArray(timeout));
args.add(Keyword.TIMEOUT).add(timeout);
}

}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/redis/clients/jedis/params/GeoAddParams.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package redis.clients.jedis.params;

import static redis.clients.jedis.Protocol.Keyword.CH;
import static redis.clients.jedis.Protocol.Keyword.NX;
import static redis.clients.jedis.Protocol.Keyword.XX;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

public class GeoAddParams implements IParams {

Expand Down Expand Up @@ -50,13 +47,13 @@ public GeoAddParams ch() {
@Override
public void addParams(CommandArguments args) {
if (nx) {
args.add(NX);
args.add(Keyword.NX);
} else if (xx) {
args.add(XX);
args.add(Keyword.XX);
}

if (ch) {
args.add(CH);
args.add(Keyword.CH);
}
}

Expand Down
Loading