diff --git a/jredisgraph.iml b/jredisgraph.iml
new file mode 100644
index 0000000..79afeb9
--- /dev/null
+++ b/jredisgraph.iml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraph.java b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
index 6cc57ce..55c4bba 100644
--- a/src/main/java/com/redislabs/redisgraph/RedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
@@ -127,4 +127,21 @@ public interface RedisGraph extends Closeable {
@Override
void close();
+
+
+ /**
+ * Executes a cypher query with parameters and redisgraph timeout.
+ * After that block the current client until all the previous cypher write queries
+ * are successfully transferred and acknowledged by at least 1 replica.
+ * If the replicationTimeout, specified in milliseconds, is reached,
+ * the method returns even if the specified number of replicas were not yet reached.
+ *
+ * @param graphId graph to be queried
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @param redisGraphTimeout
+ * @param replicationTimeout replication timeout, specified in milliseconds
+ * @return a result set
+ */
+ ResultSet replicatedQuery(String graphId, String query, Map params, long redisGraphTimeout, long replicationTimeout);
}
diff --git a/src/main/java/com/redislabs/redisgraph/ResultSet.java b/src/main/java/com/redislabs/redisgraph/ResultSet.java
index d86ff19..2a3a4b6 100644
--- a/src/main/java/com/redislabs/redisgraph/ResultSet.java
+++ b/src/main/java/com/redislabs/redisgraph/ResultSet.java
@@ -9,6 +9,8 @@ public interface ResultSet extends Iterable, Iterator {
int size();
+ long numberReplicasReached();
+
Statistics getStatistics();
Header getHeader();
diff --git a/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java b/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
index 57fce53..ea49969 100644
--- a/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
@@ -53,6 +53,19 @@ public abstract class AbstractRedisGraph implements RedisGraph {
*/
protected abstract ResultSet sendReadOnlyQuery(String graphId, String preparedQuery, long timeout);
+ /**
+ * Executes a cypher query with parameters and redisgraph timeout.
+ * After that block the current client until all the previous cypher write queries
+ * are successfully transferred and acknowledged by at least 1 replica.
+ * If the replicationTimeout, specified in milliseconds, is reached,
+ * the method returns even if the specified number of replicas were not yet reached.
+ * @param graphId graph to be queried
+ * @param preparedQuery prepared query
+ * @param replicationTimeout replication timeout, specified in milliseconds
+ * @return a result set
+ */
+ protected abstract ResultSet sendReplicatedQuery(String graphId, String preparedQuery, long redisGraphTimeout, long replicationTimeout);
+
/**
* Execute a Cypher query.
* @param graphId a graph to perform the query on
@@ -149,6 +162,25 @@ public ResultSet query(String graphId, String query, Map params,
return sendQuery(graphId, preparedQuery, timeout);
}
+
+ /**
+ * Executes a cypher query with parameters and redisgraph timeout.
+ * After that block the current client until all the previous cypher write queries
+ * are successfully transferred and acknowledged by at least 1 replica.
+ * If the replicationTimeout, specified in milliseconds, is reached,
+ * the method returns even if the specified number of replicas were not yet reached.
+ * @param graphId a graph to perform the query on.
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @param redisGraphTimeout
+ * @param replicationTimeout replication timeout, specified in milliseconds
+ * @return a result set.
+ */
+ public ResultSet replicatedQuery(String graphId, String query, Map params, long redisGraphTimeout, long replicationTimeout){
+ String preparedQuery = Utils.prepareQuery(query, params);
+ return sendReplicatedQuery(graphId, preparedQuery, redisGraphTimeout,replicationTimeout);
+ }
+
/**
* Executes a cypher read-only query with parameters and timeout.
* @param graphId a graph to perform the query on.
diff --git a/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java b/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
index 92896d0..9380db0 100644
--- a/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
@@ -8,9 +8,12 @@
import com.redislabs.redisgraph.impl.resultset.ResultSetImpl;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
+import redis.clients.jedis.Pipeline;
+import redis.clients.jedis.Response;
import redis.clients.jedis.util.SafeEncoder;
import redis.clients.jedis.exceptions.JedisDataException;
import java.util.List;
+import java.util.Map;
/**
* An implementation of RedisGraphContext. Allows sending RedisGraph and some Redis commands,
@@ -126,6 +129,42 @@ protected ResultSet sendReadOnlyQuery(String graphId, String preparedQuery, long
}
}
+ /**
+ * Executes a cypher query with parameters and redisgraph timeout.
+ * After that block the current client until all the previous cypher write queries
+ * are successfully transferred and acknowledged by at least 1 replica.
+ * If the replicationTimeout, specified in milliseconds, is reached,
+ * the method returns even if the specified number of replicas were not yet reached.
+ *
+ * @param graphId graph to be queried
+ * @param preparedQuery prepared query
+ * @param redisGraphTimeout
+ * @param replicationTimeout replication timeout, specified in milliseconds
+ * @return a result set
+ */
+ @Override
+ protected ResultSet sendReplicatedQuery(String graphId, String preparedQuery, long redisGraphTimeout, long replicationTimeout) {
+ Jedis conn = getConnection();
+ try {
+ Pipeline pipe = conn.pipelined();
+ pipe.setClient(conn.getClient());
+ Response