Skip to content

Commit 0e837cf

Browse files
upgrade redis.clients to latest 6.0.0 (#119)
* Upgrade jedis to 6.0.0 * multi transactional * review fixes --------- Co-authored-by: Barak Bar Orion <barak.bar@gmail.com>
1 parent 973765a commit 0e837cf

File tree

6 files changed

+79
-113
lines changed

6 files changed

+79
-113
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>redis.clients</groupId>
6060
<artifactId>jedis</artifactId>
61-
<version>3.10.0</version>
61+
<version>6.0.0</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>org.apache.commons</groupId>

src/main/java/com/falkordb/GraphPipeline.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.falkordb;
22

33
import redis.clients.jedis.Response;
4-
import redis.clients.jedis.commands.BasicRedisPipeline;
5-
import redis.clients.jedis.commands.BinaryRedisPipeline;
6-
import redis.clients.jedis.commands.BinaryScriptingCommandsPipeline;
7-
import redis.clients.jedis.commands.ClusterPipeline;
8-
import redis.clients.jedis.commands.MultiKeyBinaryRedisPipeline;
9-
import redis.clients.jedis.commands.MultiKeyCommandsPipeline;
10-
import redis.clients.jedis.commands.RedisPipeline;
11-
import redis.clients.jedis.commands.ScriptingCommandsPipeline;
4+
import redis.clients.jedis.commands.PipelineBinaryCommands;
5+
import redis.clients.jedis.commands.PipelineCommands;
6+
import redis.clients.jedis.commands.RedisModulePipelineCommands;
127

138
import java.io.Closeable;
149
import java.util.List;
@@ -18,10 +13,7 @@
1813
* An interface which aligned to Jedis Pipeline interface
1914
*/
2015
public interface GraphPipeline extends
21-
MultiKeyBinaryRedisPipeline,
22-
MultiKeyCommandsPipeline, ClusterPipeline,
23-
BinaryScriptingCommandsPipeline, ScriptingCommandsPipeline,
24-
BasicRedisPipeline, BinaryRedisPipeline, RedisPipeline, Closeable {
16+
PipelineCommands, PipelineBinaryCommands, RedisModulePipelineCommands, Closeable {
2517

2618
/**
2719
* Execute a Cypher query.

src/main/java/com/falkordb/GraphTransaction.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.falkordb;
22

33
import redis.clients.jedis.Response;
4-
import redis.clients.jedis.commands.BasicRedisPipeline;
5-
import redis.clients.jedis.commands.BinaryRedisPipeline;
6-
import redis.clients.jedis.commands.BinaryScriptingCommandsPipeline;
7-
import redis.clients.jedis.commands.ClusterPipeline;
8-
import redis.clients.jedis.commands.MultiKeyBinaryRedisPipeline;
9-
import redis.clients.jedis.commands.MultiKeyCommandsPipeline;
10-
import redis.clients.jedis.commands.RedisPipeline;
11-
import redis.clients.jedis.commands.ScriptingCommandsPipeline;
4+
import redis.clients.jedis.commands.PipelineBinaryCommands;
5+
import redis.clients.jedis.commands.PipelineCommands;
6+
import redis.clients.jedis.commands.RedisModulePipelineCommands;
127

138
import java.io.Closeable;
149
import java.util.List;
@@ -18,10 +13,7 @@
1813
* An interface which aligned to Jedis transactional interface
1914
*/
2015
public interface GraphTransaction extends
21-
MultiKeyBinaryRedisPipeline,
22-
MultiKeyCommandsPipeline, ClusterPipeline,
23-
BinaryScriptingCommandsPipeline, ScriptingCommandsPipeline,
24-
BasicRedisPipeline, BinaryRedisPipeline, RedisPipeline, Closeable {
16+
PipelineCommands, PipelineBinaryCommands, RedisModulePipelineCommands, Closeable {
2517

2618
/**
2719
* Execute a Cypher query.
@@ -138,12 +130,6 @@ public interface GraphTransaction extends
138130
*/
139131
void clear();
140132

141-
/**
142-
* Executes the transaction and returns a list of the executed transaction commands answers
143-
* @return a list of the executed transaction commands answers
144-
*/
145-
List<Response<?>> execGetResponse();
146-
147133
/**
148134
* Flushes all previously queued commands in a transaction and restores the connection state to normal
149135
* @return "OK" if the transaction was successfully discarded, otherwise an exception is thrown

src/main/java/com/falkordb/impl/api/GraphContextImpl.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.falkordb.impl.graph_cache.GraphCache;
1212
import com.falkordb.impl.resultset.ResultSetImpl;
1313

14-
import redis.clients.jedis.Client;
1514
import redis.clients.jedis.Jedis;
1615
import redis.clients.jedis.exceptions.JedisDataException;
1716
import redis.clients.jedis.util.SafeEncoder;
@@ -120,10 +119,10 @@ protected ResultSet sendReadOnlyQuery(String preparedQuery, long timeout) {
120119
*/
121120
@Override
122121
public GraphTransaction multi() {
123-
Client client = connection.getClient();
124-
client.multi();
125-
client.getOne();
126-
return new GraphTransactionImpl(client, this, this.cache, this.graphId);
122+
GraphTransactionImpl transaction = new GraphTransactionImpl(
123+
connection.getClient(), this, this.cache, this.graphId);
124+
transaction.multi();
125+
return transaction;
127126
}
128127

129128
/**
@@ -132,8 +131,7 @@ public GraphTransaction multi() {
132131
*/
133132
@Override
134133
public GraphPipeline pipelined() {
135-
Client client = connection.getClient();
136-
return new GraphPipelineImpl(client, this, this.cache, this.graphId);
134+
return new GraphPipelineImpl(connection.getClient(), this, this.cache, this.graphId);
137135
}
138136

139137
/**

src/main/java/com/falkordb/impl/api/GraphPipelineImpl.java

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import com.falkordb.impl.Utils;
66
import com.falkordb.impl.graph_cache.GraphCache;
77
import com.falkordb.impl.resultset.ResultSetImpl;
8-
import redis.clients.jedis.Builder;
9-
import redis.clients.jedis.BuilderFactory;
10-
import redis.clients.jedis.Client;
11-
import redis.clients.jedis.Pipeline;
12-
import redis.clients.jedis.Response;
8+
import redis.clients.jedis.*;
9+
import redis.clients.jedis.commands.ProtocolCommand;
1310

11+
import java.util.Arrays;
1412
import java.util.List;
1513
import java.util.Map;
1614

@@ -23,22 +21,27 @@ public class GraphPipelineImpl extends Pipeline implements com.falkordb.GraphPip
2321
private GraphCache cache;
2422
private final String graphId;
2523

26-
public GraphPipelineImpl(Client client, Graph graph, GraphCache cache, String graphId){
27-
super.setClient(client);
24+
public GraphPipelineImpl(Connection connection, Graph graph, GraphCache cache, String graphId){
25+
super(connection);
2826
this.graph = graph;
2927
this.cache = cache;
3028
this.graphId = graphId;
3129
}
3230

31+
protected <T> Response<T> appendWithResponse(ProtocolCommand protocolCommand, List<Object> arguments, Builder<T> builder) {
32+
CommandArguments commandArguments = new CommandArguments(protocolCommand);
33+
arguments.forEach(commandArguments::add);
34+
return this.appendCommand(new CommandObject<>(commandArguments, builder));
35+
}
36+
3337
/**
3438
* Execute a Cypher query.
3539
* @param query Cypher query
3640
* @return a response which builds the result set with the query answer.
3741
*/
3842
@Override
3943
public Response<ResultSet> query(String query) {
40-
client.sendCommand(GraphCommand.QUERY, graphId, query, Utils.COMPACT_STRING);
41-
return getResponse(new Builder<ResultSet>() {
44+
return appendWithResponse(GraphCommand.QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING), new Builder<ResultSet>() {
4245
@SuppressWarnings("unchecked")
4346
@Override
4447
public ResultSet build(Object o) {
@@ -54,8 +57,7 @@ public ResultSet build(Object o) {
5457
*/
5558
@Override
5659
public Response<ResultSet> readOnlyQuery(String query) {
57-
client.sendCommand(GraphCommand.RO_QUERY, graphId, query, Utils.COMPACT_STRING);
58-
return getResponse(new Builder<ResultSet>() {
60+
return appendWithResponse(GraphCommand.RO_QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING), new Builder<ResultSet>() {
5961
@SuppressWarnings("unchecked")
6062
@Override
6163
public ResultSet build(Object o) {
@@ -74,9 +76,8 @@ public ResultSet build(Object o) {
7476
*/
7577
@Override
7678
public Response<ResultSet> query(String query, long timeout) {
77-
client.sendCommand(GraphCommand.QUERY, graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
78-
Long.toString(timeout));
79-
return getResponse(new Builder<ResultSet>() {
79+
return appendWithResponse(GraphCommand.QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
80+
Long.toString(timeout)), new Builder<ResultSet>() {
8081
@SuppressWarnings("unchecked")
8182
@Override
8283
public ResultSet build(Object o) {
@@ -95,9 +96,8 @@ public ResultSet build(Object o) {
9596
*/
9697
@Override
9798
public Response<ResultSet> readOnlyQuery(String query, long timeout) {
98-
client.sendCommand(GraphCommand.RO_QUERY, graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
99-
Long.toString(timeout));
100-
return getResponse(new Builder<ResultSet>() {
99+
return appendWithResponse(GraphCommand.RO_QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
100+
Long.toString(timeout)), new Builder<ResultSet>() {
101101
@SuppressWarnings("unchecked")
102102
@Override
103103
public ResultSet build(Object o) {
@@ -114,9 +114,7 @@ public ResultSet build(Object o) {
114114
*/
115115
@Override
116116
public Response<ResultSet> query(String query, Map<String, Object> params) {
117-
String preparedQuery = Utils.prepareQuery(query, params);
118-
client.sendCommand(GraphCommand.QUERY, graphId, preparedQuery, Utils.COMPACT_STRING);
119-
return getResponse(new Builder<ResultSet>() {
117+
return appendWithResponse(GraphCommand.QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING), new Builder<ResultSet>() {
120118
@SuppressWarnings("unchecked")
121119
@Override
122120
public ResultSet build(Object o) {
@@ -133,9 +131,7 @@ public ResultSet build(Object o) {
133131
*/
134132
@Override
135133
public Response<ResultSet> readOnlyQuery(String query, Map<String, Object> params) {
136-
String preparedQuery = Utils.prepareQuery(query, params);
137-
client.sendCommand(GraphCommand.RO_QUERY, graphId, preparedQuery, Utils.COMPACT_STRING);
138-
return getResponse(new Builder<ResultSet>() {
134+
return appendWithResponse(GraphCommand.RO_QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING), new Builder<ResultSet>() {
139135
@SuppressWarnings("unchecked")
140136
@Override
141137
public ResultSet build(Object o) {
@@ -156,10 +152,8 @@ public ResultSet build(Object o) {
156152
*/
157153
@Override
158154
public Response<ResultSet> query(String query, Map<String, Object> params, long timeout) {
159-
String preparedQuery = Utils.prepareQuery(query, params);
160-
client.sendCommand(GraphCommand.QUERY, graphId, preparedQuery, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
161-
Long.toString(timeout));
162-
return getResponse(new Builder<ResultSet>() {
155+
return appendWithResponse(GraphCommand.QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
156+
Long.toString(timeout)), new Builder<ResultSet>() {
163157
@SuppressWarnings("unchecked")
164158
@Override
165159
public ResultSet build(Object o) {
@@ -180,11 +174,8 @@ public ResultSet build(Object o) {
180174
*/
181175
@Override
182176
public Response<ResultSet> readOnlyQuery(String query, Map<String, Object> params, long timeout) {
183-
String preparedQuery = Utils.prepareQuery(query, params);
184-
client.sendCommand(GraphCommand.RO_QUERY, graphId, preparedQuery, Utils.COMPACT_STRING,
185-
Utils.TIMEOUT_STRING,
186-
Long.toString(timeout));
187-
return getResponse(new Builder<ResultSet>() {
177+
return appendWithResponse(GraphCommand.RO_QUERY, Arrays.asList(graphId, query, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING,
178+
Long.toString(timeout)), new Builder<ResultSet>() {
188179
@SuppressWarnings("unchecked")
189180
@Override
190181
public ResultSet build(Object o) {
@@ -235,8 +226,7 @@ public Response<ResultSet> callProcedure(String procedure, List<String> args,
235226
*/
236227
@Override
237228
public Response<String> copyGraph(String destinationGraphId) {
238-
client.sendCommand(GraphCommand.COPY, graphId, destinationGraphId);
239-
return getResponse(BuilderFactory.STRING);
229+
return appendWithResponse(GraphCommand.COPY, Arrays.asList(graphId, destinationGraphId), BuilderFactory.STRING);
240230
}
241231

242232

@@ -246,10 +236,11 @@ public Response<String> copyGraph(String destinationGraphId) {
246236
*/
247237
@Override
248238
public Response<String> deleteGraph(){
239+
try {
240+
return appendWithResponse(GraphCommand.DELETE, Arrays.asList(graphId), BuilderFactory.STRING);
241+
} finally {
242+
cache.clear();
243+
}
249244

250-
client.sendCommand(GraphCommand.DELETE, graphId);
251-
Response<String> response = getResponse(BuilderFactory.STRING);
252-
cache.clear();
253-
return response;
254245
}
255246
}

0 commit comments

Comments
 (0)