Skip to content

Commit 48329d4

Browse files
author
DvirDukhan
committed
added watch support
1 parent 62e9c43 commit 48329d4

25 files changed

+781
-214
lines changed

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@
4747
</license>
4848
</licenses>
4949

50-
<repositories>
51-
<repository>
52-
<id>snapshots-repo</id>
53-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
54-
</repository>
55-
</repositories>
56-
5750
<dependencies>
5851
<dependency>
5952
<groupId>org.apache.commons</groupId>

src/main/java/com/redislabs/redisgraph/Header.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import java.util.List;
44

55
/**
6-
* Query response header interface. Represents the response schame (column names and types)
6+
* Query response header interface. Represents the response schema (column names and types)
77
*/
88
public interface Header {
99

1010

11-
public enum ResultSetColumnTypes {
11+
enum ResultSetColumnTypes {
1212
COLUMN_UNKNOWN,
1313
COLUMN_SCALAR,
1414
COLUMN_NODE,
15-
COLUMN_RELATION;
15+
COLUMN_RELATION
1616

1717
}
1818

Lines changed: 13 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,27 @@
11
package com.redislabs.redisgraph;
22

3-
import com.redislabs.redisgraph.impl.JRedisGraphTransaction;
4-
import com.redislabs.redisgraph.impl.graph_cache.GraphCache;
5-
import com.redislabs.redisgraph.impl.ResultSetImpl;
6-
import org.apache.commons.text.translate.AggregateTranslator;
7-
import org.apache.commons.text.translate.CharSequenceTranslator;
8-
import org.apache.commons.text.translate.LookupTranslator;
9-
import redis.clients.jedis.BinaryClient;
10-
import redis.clients.jedis.Client;
11-
import redis.clients.jedis.Jedis;
12-
import redis.clients.jedis.JedisPool;
13-
import redis.clients.jedis.commands.ProtocolCommand;
14-
import redis.clients.jedis.util.Pool;
15-
import redis.clients.jedis.util.SafeEncoder;
16-
173
import java.io.Closeable;
18-
import java.util.*;
19-
import java.util.concurrent.ConcurrentHashMap;
20-
import java.util.stream.Collectors;
21-
22-
23-
/**
24-
*
25-
*/
26-
public class RedisGraph implements Closeable {
27-
28-
29-
30-
private final Pool<Jedis> client;
31-
private final Map<String, GraphCache> graphCaches = new ConcurrentHashMap<>();
32-
33-
/**
34-
* Creates a client running on the local machine
35-
36-
*/
37-
public RedisGraph() {
38-
this("localhost", 6379);
39-
}
40-
41-
/**
42-
* Creates a client running on the specific host/post
43-
*
44-
* @param host Redis host
45-
* @param port Redis port
46-
*/
47-
public RedisGraph(String host, int port) {
48-
this( new JedisPool(host, port));
49-
}
50-
51-
/**
52-
* Creates a client using provided Jedis pool
53-
*
54-
* @param jedis bring your own Jedis pool
55-
*/
56-
public RedisGraph( Pool<Jedis> jedis) {
57-
58-
this.client = jedis;
59-
}
60-
61-
@Override
62-
public void close(){
63-
this.client.close();
64-
}
4+
import java.util.List;
5+
import java.util.Map;
656

7+
public interface RedisGraph extends Closeable {
668

679
/**
6810
* Execute a Cypher query with arguments
69-
*
7011
* @param graphId a graph to perform the query on
7112
* @param query Cypher query
7213
* @param args
7314
* @return a result set
7415
*/
75-
public ResultSet query(String graphId, String query, Object ...args) {
76-
String preparedQuery = Utils.prepareQuery(query, args);
77-
graphCaches.putIfAbsent(graphId, new GraphCache(graphId, this));
78-
List<Object> rawResponse = null;
79-
try(Jedis conn = getConnection()){
80-
rawResponse = (List<Object>) conn.sendCommand(Command.QUERY, graphId, preparedQuery, "--COMPACT");
81-
}
82-
return new ResultSetImpl(rawResponse, graphCaches.get(graphId));
83-
}
16+
ResultSet query(String graphId, String query, Object ...args);
8417

8518
/**
8619
* Invokes stored procedures without arguments
8720
* @param graphId a graph to perform the query on
8821
* @param procedure procedure name to invoke
8922
* @return result set with the procedure data
9023
*/
91-
public ResultSet callProcedure(String graphId, String procedure){
92-
return callProcedure(graphId, procedure, new ArrayList<>(), new HashMap<>());
93-
}
94-
24+
ResultSet callProcedure(String graphId, String procedure);
9525

9626
/**
9727
* Invokes stored procedure with arguments
@@ -100,28 +30,7 @@ public ResultSet callProcedure(String graphId, String procedure){
10030
* @param args procedure arguments
10131
* @return result set with the procedure data
10232
*/
103-
public ResultSet callProcedure(String graphId, String procedure, List<String> args ){
104-
return callProcedure(graphId, procedure, args, new HashMap<>());
105-
}
106-
107-
/**
108-
* Deletes the entire graph
109-
* @param graphId graph to delete
110-
* @return delete running time statistics
111-
*/
112-
public String deleteGraph(String graphId) {
113-
//clear local state
114-
graphCaches.remove(graphId);
115-
try (Jedis conn = getConnection()) {
116-
return SafeEncoder.encode((byte[]) conn.sendCommand(Command.DELETE, graphId));
117-
}
118-
119-
}
120-
121-
private Jedis getConnection() {
122-
return this.client.getResource();
123-
}
124-
33+
ResultSet callProcedure(String graphId, String procedure, List<String> args);
12534

12635
/**
12736
* Invoke a stored procedure
@@ -131,21 +40,13 @@ private Jedis getConnection() {
13140
* @param kwargs - procedure output arguments
13241
* @return result set with the procedure data
13342
*/
134-
public ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs ){
43+
ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs);
13544

136-
String preparedProcedure = Utils.prepareProcedure(procedure, args, kwargs);
137-
return query(graphId, preparedProcedure);
138-
}
139-
140-
public JRedisGraphTransaction multi(){
141-
Jedis jedis = getConnection();
142-
Client client = jedis.getClient();
143-
client.multi();
144-
client.getOne();
145-
return new JRedisGraphTransaction(client,this, this.graphCaches);
146-
}
45+
/**
46+
* Deletes the entire graph
47+
* @param graphId graph to delete
48+
* @return delete running time statistics
49+
*/
50+
String deleteGraph(String graphId);
14751

148-
public Map<String, GraphCache> getGraphCaches() {
149-
return graphCaches;
150-
}
15152
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.redislabs.redisgraph;
2+
3+
import redis.clients.jedis.Jedis;
4+
5+
public interface RedisGraphContexted extends RedisGraph {
6+
7+
8+
/**
9+
* Returns implementing class connection context
10+
* @return Jedis connection
11+
*/
12+
Jedis getConnectionContext();
13+
14+
/**
15+
* Returns a Redis transactional object, over the connection context, with graph API capabilities
16+
* @return Redis transactional object, over the connection context, with graph API capabilities
17+
*/
18+
RedisGraphTransaction multi();
19+
20+
/**
21+
* Perform watch over given Redis keys
22+
* @param keys
23+
* @return "OK"
24+
*/
25+
String watch(String... keys);
26+
27+
/**
28+
* Removes watch from all keys
29+
* @return
30+
*/
31+
String unwatch();
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.redislabs.redisgraph;
2+
3+
import redis.clients.jedis.Jedis;
4+
5+
public interface RedisGraphGeneralContext extends RedisGraph {
6+
7+
/**
8+
* Generate a connection bounded api
9+
* @return a connection bounded api
10+
*/
11+
RedisGraphContexted getContextedAPI();
12+
13+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.redislabs.redisgraph;
2+
3+
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;
12+
13+
import java.io.Closeable;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
/**
18+
* An interface which aligned to Jedis transactional interface
19+
*/
20+
public interface RedisGraphTransaction extends
21+
MultiKeyBinaryRedisPipeline,
22+
MultiKeyCommandsPipeline, ClusterPipeline,
23+
BinaryScriptingCommandsPipeline, ScriptingCommandsPipeline,
24+
BasicRedisPipeline, BinaryRedisPipeline, RedisPipeline, Closeable {
25+
/**
26+
* Execute a Cypher query with arguments
27+
* @param graphId a graph to perform the query on
28+
* @param query Cypher query
29+
* @param args
30+
* @return a response which builds the result set with the query answer
31+
*/
32+
Response<ResultSet> query(String graphId, String query, Object ...args);
33+
34+
/**
35+
* Invokes stored procedures without arguments
36+
* @param graphId a graph to perform the query on
37+
* @param procedure procedure name to invoke
38+
* @return a response which builds result set with the procedure data
39+
*/
40+
Response<ResultSet> callProcedure(String graphId, String procedure);
41+
42+
/**
43+
* Invokes stored procedure with arguments
44+
* @param graphId a graph to perform the query on
45+
* @param procedure procedure name to invoke
46+
* @param args procedure arguments
47+
* @return a response which builds result set with the procedure data
48+
*/
49+
Response<ResultSet> callProcedure(String graphId, String procedure, List<String> args);
50+
51+
/**
52+
* Invoke a stored procedure
53+
* @param graphId a graph to perform the query on
54+
* @param procedure - procedure to execute
55+
* @param args - procedure arguments
56+
* @param kwargs - procedure output arguments
57+
* @return a response which builds result set with the procedure data
58+
*/
59+
Response<ResultSet> callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs);
60+
61+
/**
62+
* Deletes the entire graph
63+
* @param graphId graph to delete
64+
* @return a response which builds the delete running time statistics
65+
*/
66+
Response<String> deleteGraph(String graphId);
67+
68+
69+
/**
70+
* executes the transaction
71+
* @return a list of the executed transaction commands answers, in case of successful transaction, null otherwise
72+
*/
73+
List<Object> exec();
74+
75+
/**
76+
* If object is in transaction mode,
77+
* flushes all previously queued commands in a transaction and restores the connection state to normal
78+
*/
79+
void clear();
80+
81+
/**
82+
*
83+
* @return
84+
*/
85+
List<Response<?>> execGetResponse();
86+
87+
/**
88+
* Flushes all previously queued commands in a transaction and restores the connection state to normal
89+
*/
90+
String discard();
91+
}

src/main/java/com/redislabs/redisgraph/ResultSet.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.redislabs.redisgraph;
22

33
import java.util.Iterator;
4-
import java.util.List;
54

65
/**
76
* Hold a query result
87
*/
98
public interface ResultSet extends Iterator<Record> {
109

11-
public enum ResultSetScalarTypes {
10+
enum ResultSetScalarTypes {
1211
PROPERTY_UNKNOWN,
1312
PROPERTY_NULL,
1413
PROPERTY_STRING,
@@ -17,7 +16,7 @@ public enum ResultSetScalarTypes {
1716
PROPERTY_DOUBLE,
1817
}
1918

20-
public int size();
19+
int size();
2120

2221
Statistics getStatistics();
2322

src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public class Edge extends GraphEntity {
1010

11-
//memebers
11+
//members
1212
private String relationshipType;
1313
private int source;
1414
private int destination;

src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public abstract class GraphEntity {
1616

1717
//members
1818

19-
protected int id;
20-
protected final Map<String, Property> propertyMap = new HashMap<>();
19+
int id;
20+
final Map<String, Property> propertyMap = new HashMap<>();
2121

2222

2323
//setters & getters

src/main/java/com/redislabs/redisgraph/graph_entities/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void removeLabel(String label) {
2828

2929
/**
3030
* @param index - label index
31-
* @return the proprty label
31+
* @return the property label
3232
* @throws IndexOutOfBoundsException if the index is out of range
3333
* ({@code index < 0 || index >= getNumberOfLabels()})
3434
*/

0 commit comments

Comments
 (0)