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 RedisGraph #2941

Merged
merged 6 commits into from
Mar 20, 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
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/ClusterPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ protected HostAndPort getNodeKey(CommandArguments args) {
protected Connection getConnection(HostAndPort nodeKey) {
return provider.getConnection(nodeKey);
}

/**
* This method must be called after constructor, if graph commands are going to be used.
*/
public void prepareGraphCommands() {
super.prepareGraphCommands(provider);
}
}
58 changes: 58 additions & 0 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import redis.clients.jedis.commands.PipelineBinaryCommands;
import redis.clients.jedis.commands.PipelineCommands;
import redis.clients.jedis.commands.RedisModulePipelineCommands;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.graph.ResultSet;
import redis.clients.jedis.json.JsonSetParams;
import redis.clients.jedis.json.Path;
import redis.clients.jedis.json.Path2;
import redis.clients.jedis.params.*;
import redis.clients.jedis.providers.ConnectionProvider;
import redis.clients.jedis.resps.*;
import redis.clients.jedis.search.IndexOptions;
import redis.clients.jedis.search.Query;
Expand All @@ -39,6 +42,7 @@ public abstract class MultiNodePipelineBase implements PipelineCommands, Pipelin
private volatile boolean synced;

private final CommandObjects commandObjects;
private GraphCommandObjects graphCommandObjects;

public MultiNodePipelineBase(CommandObjects commandObjects) {
pipelinedResponses = new LinkedHashMap<>();
Expand All @@ -47,6 +51,13 @@ public MultiNodePipelineBase(CommandObjects commandObjects) {
this.commandObjects = commandObjects;
}

/**
* Sub-classes must call this method, if graph commands are going to be used.
*/
protected final void prepareGraphCommands(ConnectionProvider connectionProvider) {
this.graphCommandObjects = new GraphCommandObjects(connectionProvider);
}

protected abstract HostAndPort getNodeKey(CommandArguments args);

protected abstract Connection getConnection(HostAndPort nodeKey);
Expand Down Expand Up @@ -3952,6 +3963,53 @@ public Response<Map<String, Object>> topkInfo(String key) {
}
// RedisBloom commands

// RedisGraph commands
@Override
public Response<ResultSet> graphQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphQuery(name, query));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params, timeout));
}

@Override
public Response<String> graphDelete(String name) {
return appendCommand(graphCommandObjects.graphDelete(name));
}
// RedisGraph commands

public Response<Long> waitReplicas(int replicas, long timeout) {
return appendCommand(commandObjects.waitReplicas(replicas, timeout));
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/redis/clients/jedis/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.commands.RedisModulePipelineCommands;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.graph.ResultSet;
import redis.clients.jedis.json.JsonSetParams;
import redis.clients.jedis.json.Path;
import redis.clients.jedis.json.Path2;
Expand All @@ -38,19 +40,22 @@ public class Pipeline extends Queable implements PipelineCommands, PipelineBinar
protected final Connection connection;
// private final Jedis jedis;
private final CommandObjects commandObjects;
private final GraphCommandObjects graphCommandObjects;

public Pipeline(Connection connection) {
// super(connection);
this.connection = connection;
// this.jedis = null;
this.commandObjects = new CommandObjects();
this.graphCommandObjects = new GraphCommandObjects(this.connection);
}

public Pipeline(Jedis jedis) {
// super(jedis.getConnection());
this.connection = jedis.getConnection();
// this.jedis = jedis;
this.commandObjects = new CommandObjects();
this.graphCommandObjects = new GraphCommandObjects(this.connection);
}

public final <T> Response<T> appendCommand(CommandObject<T> commandObject) {
Expand Down Expand Up @@ -3960,6 +3965,53 @@ public Response<Map<String, Object>> topkInfo(String key) {
}
// RedisBloom commands

// RedisGraph commands
@Override
public Response<ResultSet> graphQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphQuery(name, query));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params, timeout));
}

@Override
public Response<String> graphDelete(String name) {
return appendCommand(graphCommandObjects.graphDelete(name));
}
// RedisGraph commands

public Response<Long> waitReplicas(int replicas, long timeout) {
return appendCommand(commandObjects.waitReplicas(replicas, timeout));
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ protected HostAndPort getNodeKey(CommandArguments args) {
protected Connection getConnection(HostAndPort nodeKey) {
return provider.getConnection(nodeKey);
}

/**
* This method must be called after constructor, if graph commands are going to be used.
*/
public void prepareGraphCommands() {
super.prepareGraphCommands(provider);
}
}
51 changes: 51 additions & 0 deletions src/main/java/redis/clients/jedis/TransactionBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import redis.clients.jedis.commands.RedisModulePipelineCommands;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.graph.ResultSet;
import redis.clients.jedis.json.JsonSetParams;
import redis.clients.jedis.json.Path;
import redis.clients.jedis.json.Path2;
Expand All @@ -43,6 +45,7 @@ public abstract class TransactionBase extends Queable implements PipelineCommand

protected final Connection connection;
private final CommandObjects commandObjects;
private final GraphCommandObjects graphCommandObjects;

private boolean broken = false;
private boolean inWatch = false;
Expand All @@ -58,6 +61,7 @@ public TransactionBase(Connection connection) {
public TransactionBase(Connection connection, boolean doMulti) {
this.connection = connection;
this.commandObjects = new CommandObjects();
this.graphCommandObjects = new GraphCommandObjects(this.connection);
if (doMulti) multi();
}

Expand Down Expand Up @@ -4029,6 +4033,53 @@ public Response<Map<String, Object>> topkInfo(String key) {
}
// RedisBloom commands

// RedisGraph commands
@Override
public Response<ResultSet> graphQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphQuery(name, query));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, timeout));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params));
}

@Override
public Response<ResultSet> graphQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphQuery(name, query, params, timeout));
}

@Override
public Response<ResultSet> graphReadonlyQuery(String name, String query, Map<String, Object> params, long timeout) {
return appendCommand(graphCommandObjects.graphReadonlyQuery(name, query, params, timeout));
}

@Override
public Response<String> graphDelete(String name) {
return appendCommand(graphCommandObjects.graphDelete(name));
}
// RedisGraph commands

public Response<Long> waitReplicas(int replicas, long timeout) {
return appendCommand(commandObjects.waitReplicas(replicas, timeout));
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import redis.clients.jedis.commands.SampleKeyedCommands;
import redis.clients.jedis.commands.RedisModuleCommands;
import redis.clients.jedis.executors.*;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.graph.ResultSet;
import redis.clients.jedis.json.JsonSetParams;
import redis.clients.jedis.json.Path;
import redis.clients.jedis.json.Path2;
Expand All @@ -45,6 +47,7 @@ public class UnifiedJedis implements JedisCommands, JedisBinaryCommands,
protected final ConnectionProvider provider;
protected final CommandExecutor executor;
private final CommandObjects commandObjects;
private final GraphCommandObjects graphCommandObjects = new GraphCommandObjects(this);

public UnifiedJedis() {
this(new HostAndPort(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT));
Expand Down Expand Up @@ -4066,6 +4069,53 @@ public Map<String, Object> topkInfo(String key) {
}
// RedisBloom commands

// RedisGraph commands
@Override
public ResultSet graphQuery(String name, String query) {
return executeCommand(graphCommandObjects.graphQuery(name, query));
}

@Override
public ResultSet graphReadonlyQuery(String name, String query) {
return executeCommand(graphCommandObjects.graphReadonlyQuery(name, query));
}

@Override
public ResultSet graphQuery(String name, String query, long timeout) {
return executeCommand(graphCommandObjects.graphQuery(name, query, timeout));
}

@Override
public ResultSet graphReadonlyQuery(String name, String query, long timeout) {
return executeCommand(graphCommandObjects.graphReadonlyQuery(name, query, timeout));
}

@Override
public ResultSet graphQuery(String name, String query, Map<String, Object> params) {
return executeCommand(graphCommandObjects.graphQuery(name, query, params));
}

@Override
public ResultSet graphReadonlyQuery(String name, String query, Map<String, Object> params) {
return executeCommand(graphCommandObjects.graphReadonlyQuery(name, query, params));
}

@Override
public ResultSet graphQuery(String name, String query, Map<String, Object> params, long timeout) {
return executeCommand(graphCommandObjects.graphQuery(name, query, params, timeout));
}

@Override
public ResultSet graphReadonlyQuery(String name, String query, Map<String, Object> params, long timeout) {
return executeCommand(graphCommandObjects.graphReadonlyQuery(name, query, params, timeout));
}

@Override
public String graphDelete(String name) {
return executeCommand(graphCommandObjects.graphDelete(name));
}
// RedisGraph commands

public Object sendCommand(ProtocolCommand cmd) {
return executeCommand(commandObjects.commandArguments(cmd));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.bloom.RedisBloomCommands;
import redis.clients.jedis.graph.RedisGraphCommands;
import redis.clients.jedis.json.RedisJsonCommands;
import redis.clients.jedis.search.RediSearchCommands;
import redis.clients.jedis.timeseries.RedisTimeSeriesCommands;
Expand All @@ -9,6 +10,7 @@ public interface RedisModuleCommands extends
RediSearchCommands,
RedisJsonCommands,
RedisTimeSeriesCommands,
RedisBloomCommands {
RedisBloomCommands,
RedisGraphCommands {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.bloom.RedisBloomPipelineCommands;
import redis.clients.jedis.graph.RedisGraphPipelineCommands;
import redis.clients.jedis.json.RedisJsonPipelineCommands;
import redis.clients.jedis.search.RediSearchPipelineCommands;
import redis.clients.jedis.timeseries.RedisTimeSeriesPipelineCommands;
Expand All @@ -9,6 +10,7 @@ public interface RedisModulePipelineCommands extends
RediSearchPipelineCommands,
RedisJsonPipelineCommands,
RedisTimeSeriesPipelineCommands,
RedisBloomPipelineCommands {
RedisBloomPipelineCommands,
RedisGraphPipelineCommands {

}
Loading