Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MODULE LOADEX command #3238

Merged
merged 2 commits into from
Dec 11, 2022
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
28 changes: 18 additions & 10 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3558,14 +3558,14 @@ public List<Object> roleBinary() {
@Override
public List<byte[]> configGet(final byte[] pattern) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.GET.getRaw(), pattern);
connection.sendCommand(Command.CONFIG, Keyword.GET.getRaw(), pattern);
return connection.getBinaryMultiBulkReply();
}

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

Expand All @@ -3575,7 +3575,7 @@ public List<byte[]> configGet(byte[]... patterns) {
@Override
public String configResetStat() {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.RESETSTAT);
connection.sendCommand(Command.CONFIG, Keyword.RESETSTAT);
return connection.getStatusCodeReply();
}

Expand Down Expand Up @@ -3608,7 +3608,7 @@ public String configResetStat() {
@Override
public String configRewrite() {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.REWRITE);
connection.sendCommand(Command.CONFIG, Keyword.REWRITE);
return connection.getStatusCodeReply();
}

Expand Down Expand Up @@ -3644,14 +3644,14 @@ public String configRewrite() {
@Override
public String configSet(final byte[] parameter, final byte[] value) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.SET.getRaw(), parameter, value);
connection.sendCommand(Command.CONFIG, Keyword.SET.getRaw(), parameter, value);
return connection.getStatusCodeReply();
}

@Override
public String configSet(final byte[]... parameterValues) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, joinParameters(Keyword.SET.getRaw(), parameterValues));
connection.sendCommand(Command.CONFIG, joinParameters(Keyword.SET.getRaw(), parameterValues));
return connection.getStatusCodeReply();
}

Expand Down Expand Up @@ -7844,14 +7844,14 @@ public List<Object> role() {
@Override
public List<String> configGet(final String pattern) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.GET.name(), pattern);
connection.sendCommand(Command.CONFIG, Keyword.GET.name(), pattern);
return connection.getMultiBulkReply();
}

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

Expand Down Expand Up @@ -7887,14 +7887,14 @@ public List<String> configGet(String... patterns) {
@Override
public String configSet(final String parameter, final String value) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, Keyword.SET.name(), parameter, value);
connection.sendCommand(Command.CONFIG, Keyword.SET.name(), parameter, value);
return connection.getStatusCodeReply();
}

@Override
public String configSet(final String... parameterValues) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, joinParameters(Keyword.SET.name(), parameterValues));
connection.sendCommand(Command.CONFIG, joinParameters(Keyword.SET.name(), parameterValues));
return connection.getStatusCodeReply();
}

Expand Down Expand Up @@ -9112,6 +9112,14 @@ public String moduleLoad(String path, String... args) {
return connection.getStatusCodeReply();
}

@Override
public String moduleLoadEx(String path, ModuleLoadExParams params) {
checkIsInMultiOrPipeline();
connection.sendCommand(new CommandArguments(Command.MODULE).add(LOADEX).add(path)
.addParams(params));
return connection.getStatusCodeReply();
}

@Override
public String moduleUnload(final String name) {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static enum Keyword implements Rawable {
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,
MODULE, ACLCAT, PATTERN, DOCTOR, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG, ARGS,
@Deprecated ASC, @Deprecated DESC, @Deprecated LCS, @Deprecated STRINGS;

private final byte[] raw;
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/redis/clients/jedis/commands/ModuleCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,57 @@

import java.util.List;
import redis.clients.jedis.Module;
import redis.clients.jedis.params.ModuleLoadExParams;

public interface ModuleCommands {

/**
* Load and initialize the Redis module from the dynamic library specified by the path argument.
*
* @param path should be the absolute path of the library, including the full filename
* @return OK
*/
String moduleLoad(String path);

/**
* Load and initialize the Redis module from the dynamic library specified by the path argument.
*
* @param path should be the absolute path of the library, including the full filename
* @param args additional arguments are passed unmodified to the module
* @return OK
*/
String moduleLoad(String path, String... args);

/**
* Loads a module from a dynamic library at runtime with configuration directives.
* <p>
* This is an extended version of the MODULE LOAD command.
* <p>
* It loads and initializes the Redis module from the dynamic library specified by the path
* argument. The path should be the absolute path of the library, including the full filename.
* <p>
* You can use the optional CONFIG argument to provide the module with configuration directives.
* Any additional arguments that follow the ARGS keyword are passed unmodified to the module.
*
* @param path should be the absolute path of the library, including the full filename
* @param params as in description
* @return OK
*/
String moduleLoadEx(String path, ModuleLoadExParams params);

/**
* Unload the module specified by name. Note that the module's name is reported by the
* {@link ModuleCommands#moduleList() MODULE LIST} command, and may differ from the dynamic library's filename.
* {@link ModuleCommands#moduleList() MODULE LIST} command, and may differ from the dynamic
* library's filename.
*
* @param name
* @return OK
*/
String moduleUnload(String name);

/**
* Return information about the modules loaded to the server.
*
* @return list of {@link Module}
*/
List<Module> moduleList();
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/redis/clients/jedis/params/ModuleLoadExParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package redis.clients.jedis.params;

import static redis.clients.jedis.Protocol.Keyword.ARGS;
import static redis.clients.jedis.Protocol.Keyword.CONFIG;

import java.util.ArrayList;
import java.util.List;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.util.KeyValue;

public class ModuleLoadExParams implements IParams {

private final List<KeyValue<String, String>> configs = new ArrayList<>();
private final List<String> args = new ArrayList<>();

public ModuleLoadExParams() {
}

public ModuleLoadExParams moduleLoadexParams() {
return new ModuleLoadExParams();
}

public ModuleLoadExParams config(String name, String value) {
this.configs.add(KeyValue.of(name, value));
return this;
}

public ModuleLoadExParams arg(String arg) {
this.args.add(arg);
return this;
}

@Override
public void addParams(CommandArguments args) {

this.configs.forEach(kv -> args.add(CONFIG).add(kv.getKey()).add(kv.getValue()));

if (!this.args.isEmpty()) {
args.add(ARGS).addObjects(this.args);
}
}
}