Skip to content

Commit

Permalink
Merge ae8a099 into 5c299e2
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 5, 2023
2 parents 5c299e2 + ae8a099 commit 872ee0b
Show file tree
Hide file tree
Showing 27 changed files with 739 additions and 470 deletions.
376 changes: 190 additions & 186 deletions src/main/java/redis/clients/jedis/BuilderFactory.java

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,7 @@ public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xread(
Set<Map.Entry<String, StreamEntryID>> entrySet = streams.entrySet();
entrySet.forEach(entry -> args.key(entry.getKey()));
entrySet.forEach(entry -> args.add(entry.getValue()));
return new CommandObject<>(args, getStreamReadResponseBuilder());
return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE);
}

public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xreadGroup(
Expand All @@ -2647,7 +2647,7 @@ public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xreadGrou
Set<Map.Entry<String, StreamEntryID>> entrySet = streams.entrySet();
entrySet.forEach(entry -> args.key(entry.getKey()));
entrySet.forEach(entry -> args.add(entry.getValue()));
return new CommandObject<>(args, getStreamReadResponseBuilder());
return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE);
}

public final CommandObject<List<byte[]>> xread(XReadParams xReadParams, Map.Entry<byte[], byte[]>... streams) {
Expand All @@ -2674,11 +2674,6 @@ public final CommandObject<List<byte[]>> xreadGroup(byte[] groupName, byte[] con
}
return new CommandObject<>(args, BuilderFactory.BINARY_LIST);
}

private Builder<List<Map.Entry<String, List<StreamEntry>>>> getStreamReadResponseBuilder() {
if (proto == RedisProtocol.RESP3) return BuilderFactory.STREAM_READ_RESPONSE_RESP3;
return BuilderFactory.STREAM_READ_RESPONSE;
}
// Stream commands

// Scripting commands
Expand Down
76 changes: 40 additions & 36 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3572,17 +3572,17 @@ public List<Object> roleBinary() {
* @return Bulk reply.
*/
@Override
public List<byte[]> configGet(final byte[] pattern) {
public Map<byte[], byte[]> configGet(final byte[] pattern) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.CONFIG, Keyword.GET.getRaw(), pattern);
return connection.getBinaryMultiBulkReply();
return BuilderFactory.BINARY_MAP.build(connection.getOne());
}

@Override
public List<byte[]> configGet(byte[]... patterns) {
public Map<byte[], byte[]> configGet(byte[]... patterns) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.CONFIG, joinParameters(Keyword.GET.getRaw(), patterns));
return connection.getBinaryMultiBulkReply();
return BuilderFactory.BINARY_MAP.build(connection.getOne());
}

/**
Expand Down Expand Up @@ -3671,6 +3671,15 @@ public String configSet(final byte[]... parameterValues) {
return connection.getStatusCodeReply();
}

@Override
public String configSetBinary(Map<byte[], byte[]> parameterValues) {
checkIsInMultiOrPipeline();
CommandArguments args = new CommandArguments(Command.CONFIG).add(Keyword.SET);
parameterValues.forEach((k, v) -> args.add(k).add(v));
connection.sendCommand(args);
return connection.getStatusCodeReply();
}

@Override
public long strlen(final byte[] key) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -4109,23 +4118,16 @@ public String aclSetUser(byte[] name) {
}

@Override
public String aclSetUser(byte[] name, byte[]... keys) {
public String aclSetUser(byte[] name, byte[]... rules) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, joinParameters(SETUSER.getRaw(), name, keys));
connection.sendCommand(ACL, joinParameters(SETUSER.getRaw(), name, rules));
return connection.getStatusCodeReply();
}

@Override
public long aclDelUser(byte[] name) {
public long aclDelUser(byte[]... names) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, DELUSER.getRaw(), name);
return connection.getIntegerReply();
}

@Override
public long aclDelUser(byte[] name, byte[]... names) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, joinParameters(DELUSER.getRaw(), name, names));
connection.sendCommand(ACL, joinParameters(DELUSER.getRaw(), names));
return connection.getIntegerReply();
}

Expand Down Expand Up @@ -7864,17 +7866,17 @@ public List<Object> role() {
* @return Bulk reply.
*/
@Override
public List<String> configGet(final String pattern) {
public Map<String, String> configGet(final String pattern) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.CONFIG, Keyword.GET.name(), pattern);
return connection.getMultiBulkReply();
return BuilderFactory.STRING_MAP.build(connection.getOne());
}

@Override
public List<String> configGet(String... patterns) {
public Map<String, String> configGet(String... patterns) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.CONFIG, joinParameters(Keyword.GET.name(), patterns));
return connection.getMultiBulkReply();
return BuilderFactory.STRING_MAP.build(connection.getOne());
}

/**
Expand Down Expand Up @@ -7920,6 +7922,15 @@ public String configSet(final String... parameterValues) {
return connection.getStatusCodeReply();
}

@Override
public String configSet(Map<String, String> parameterValues) {
checkIsInMultiOrPipeline();
CommandArguments args = new CommandArguments(Command.CONFIG).add(Keyword.SET);
parameterValues.forEach((k, v) -> args.add(k).add(v));
connection.sendCommand(args);
return connection.getStatusCodeReply();
}

public long publish(final String channel, final String message) {
checkIsInMultiOrPipeline();
connection.sendCommand(PUBLISH, channel, message);
Expand Down Expand Up @@ -8360,31 +8371,24 @@ public String aclSetUser(final String name) {
}

@Override
public String aclSetUser(String name, String... params) {
public String aclSetUser(String name, String... rules) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, joinParameters(SETUSER.name(), name, params));
connection.sendCommand(ACL, joinParameters(SETUSER.name(), name, rules));
return connection.getStatusCodeReply();
}

@Override
public long aclDelUser(final String name) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, DELUSER.name(), name);
return connection.getIntegerReply();
}

@Override
public long aclDelUser(final String name, String... names) {
public long aclDelUser(final String... names) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, joinParameters(DELUSER.name(), name, names));
connection.sendCommand(ACL, joinParameters(DELUSER.name(), names));
return connection.getIntegerReply();
}

@Override
public AccessControlUser aclGetUser(final String name) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, GETUSER.name(), name);
return BuilderFactory.ACCESS_CONTROL_USER.build(connection.getObjectMultiBulkReply());
return BuilderFactory.ACCESS_CONTROL_USER.build(connection.getOne());
}

@Override
Expand Down Expand Up @@ -8412,28 +8416,28 @@ public String aclWhoAmI() {
public List<String> aclCat() {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, CAT);
return BuilderFactory.STRING_LIST.build(connection.getObjectMultiBulkReply());
return BuilderFactory.STRING_LIST.build(connection.getOne());
}

@Override
public List<String> aclCat(String category) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, CAT.name(), category);
return BuilderFactory.STRING_LIST.build(connection.getObjectMultiBulkReply());
return BuilderFactory.STRING_LIST.build(connection.getOne());
}

@Override
public List<AccessControlLogEntry> aclLog() {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, LOG);
return BuilderFactory.ACCESS_CONTROL_LOG_ENTRY_LIST.build(connection.getObjectMultiBulkReply());
return BuilderFactory.ACCESS_CONTROL_LOG_ENTRY_LIST.build(connection.getOne());
}

@Override
public List<AccessControlLogEntry> aclLog(int limit) {
checkIsInMultiOrPipeline();
connection.sendCommand(ACL, LOG.getRaw(), toByteArray(limit));
return BuilderFactory.ACCESS_CONTROL_LOG_ENTRY_LIST.build(connection.getObjectMultiBulkReply());
return BuilderFactory.ACCESS_CONTROL_LOG_ENTRY_LIST.build(connection.getOne());
}

@Override
Expand Down Expand Up @@ -9185,7 +9189,7 @@ public String moduleUnload(final String name) {
public List<Module> moduleList() {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.MODULE, LIST);
return BuilderFactory.MODULE_LIST.build(connection.getObjectMultiBulkReply());
return BuilderFactory.MODULE_LIST.build(connection.getOne());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/Module.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package redis.clients.jedis;

// TODO: 'resps' package
// TODO: remove
public class Module {

private final String name;
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import redis.clients.jedis.exceptions.*;
import redis.clients.jedis.args.Rawable;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.util.KeyValue;
import redis.clients.jedis.util.RedisInputStream;
import redis.clients.jedis.util.RedisOutputStream;
import redis.clients.jedis.util.SafeEncoder;
Expand Down Expand Up @@ -133,17 +134,14 @@ private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) {
private static Object process(final RedisInputStream is) {
final byte b = is.readByte();
//System.out.println((char) b);
int num;
switch (b) {
case PLUS_BYTE:
return is.readLineBytes();
case DOLLAR_BYTE:
case EQUAL_BYTE:
return processBulkReply(is);
case ASTERISK_BYTE:
num = is.readIntCrLf();
if (num == -1) return null;
return processMultiBulkReply(num, is);
return processMultiBulkReply(is);
case UNDERSCORE_BYTE:
return is.readNullCrLf();
case HASH_BYTE:
Expand All @@ -155,17 +153,11 @@ private static Object process(final RedisInputStream is) {
case LEFT_BRACE_BYTE:
return is.readBigIntegerCrLf();
case PERCENT_BYTE: // TODO: currently just to start working with HELLO
num = is.readIntCrLf();
if (num == -1) return null;
return processMultiBulkReply(2 * num, is);
return processMapKeyValueReply(is);
case TILDE_BYTE: // TODO:
num = is.readIntCrLf();
if (num == -1) return null;
return processMultiBulkReply(num, is);
return processMultiBulkReply(is);
case GREATER_THAN_BYTE:
num = is.readIntCrLf();
if (num == -1) return null;
return processMultiBulkReply(num, is);
return processMultiBulkReply(is);
case MINUS_BYTE:
processError(is);
return null;
Expand Down Expand Up @@ -198,9 +190,10 @@ private static byte[] processBulkReply(final RedisInputStream is) {
return read;
}

// private static List<Object> processMultiBulkReply(final RedisInputStream is) {
private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
// final int num = is.readIntCrLf();
private static List<Object> processMultiBulkReply(final RedisInputStream is) {
// private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
final int num = is.readIntCrLf();
if (num == -1) return null;
final List<Object> ret = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
try {
Expand All @@ -212,6 +205,18 @@ private static List<Object> processMultiBulkReply(final int num, final RedisInpu
return ret;
}

// private static List<Object> processMultiBulkReply(final RedisInputStream is) {
// private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
private static List<KeyValue> processMapKeyValueReply(final RedisInputStream is) {
final int num = is.readIntCrLf();
if (num == -1) return null;
final List<KeyValue> ret = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
ret.add(new KeyValue(process(is), process(is)));
}
return ret;
}

public static Object read(final RedisInputStream is) {
return process(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,20 @@ public interface AccessControlLogBinaryCommands {
* Create an ACL for the specified user, while specifying the rules.
*
* @param name user who receives an acl
* @param keys the acl rules for the specified user
* @param rules the acl rules for the specified user
* @see <a href="https://redis.io/commands/acl-setuser">ACL SETUSER</a>
* @return A string containing OK on success
*/
String aclSetUser(byte[] name, byte[]... keys);
String aclSetUser(byte[] name, byte[]... rules);

/**
* Delete the specified user, from the ACL.
*
* @param name The username to delete
* @param names The username to delete
* @see <a href="https://redis.io/commands/acl-deluser">ACL DELUSER</a>
* @return The number of users delete
*/
long aclDelUser(byte[] name);

/**
* Delete the specified users, from the ACL.
*
* @param name The username to delete
* @param names Other usernames to delete
* @see <a href="https://redis.io/commands/acl-deluser">ACL DELUSER</a>
* @return The number of users delete
*/
long aclDelUser(byte[] name, byte[]... names);
long aclDelUser(byte[]... names);

/**
* Show the available ACL categories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,20 @@ public interface AccessControlLogCommands {
* Create an ACL for the specified user, while specifying the rules.
*
* @param name user who receives an acl
* @param keys the acl rules for the specified user
* @param rules the acl rules for the specified user
* @see <a href="https://redis.io/commands/acl-setuser">ACL SETUSER</a>
* @return A string containing OK on success
*/
String aclSetUser(String name, String... keys);
String aclSetUser(String name, String... rules);

/**
* Delete the specified user, from the ACL.
*
* @param name The username to delete
* @param names The usernames to delete
* @see <a href="https://redis.io/commands/acl-deluser">ACL DELUSER</a>
* @return The number of users delete
*/
long aclDelUser(String name);

/**
* Delete the specified users, from the ACL.
*
* @param name The username to delete
* @param names Other usernames to delete
* @see <a href="https://redis.io/commands/acl-deluser">ACL DELUSER</a>
* @return The number of users delete
*/
long aclDelUser(String name, String... names);
long aclDelUser(String... names);

/**
* Show the available ACL categories.
Expand Down
Loading

0 comments on commit 872ee0b

Please sign in to comment.