Skip to content
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
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ and
```

# Example: Using the Java Client

## Up to 2.0.0
```java
package com.redislabs.redisgraph;

Expand All @@ -80,3 +80,60 @@ public class RedisGraphExample {
}

```
## From 2.0.0

```java
package com.redislabs.redisgraph;

import com.redislabs.redisgraph.graph_entities.Edge;
import com.redislabs.redisgraph.graph_entities.Node;
import com.redislabs.redisgraph.impl.api.RedisGraph;

import java.util.List;

public class RedisGraphExample {
public static void main(String[] args) {
// general context api. Not bound to graph key or connection
RedisGraph graph = new RedisGraph();

// send queries to a specific graph called "social"
graph.query("social","CREATE (:person{name:'roi',age:32})");
graph.query("social","CREATE (:person{name:%s,age:%d})", "amit", 30);
graph.query("social","MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)");

ResultSet resultSet = graph.query("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b");
while(resultSet.hasNext()) {
Record record = resultSet.next();
// get values
Node a = record.getValue("a");
Edge r = record.getValue("r");

//print record
System.out.println(record.toString());
}

// delete graph
graph.deleteGraph("social");

// get connection context - closable object
try(RedisGraphContext context = graph.getContext()) {
context.query("contextSocial","CREATE (:person{name:'roi',age:32})");
context.query("contextSocial","CREATE (:person{name:%s,age:%d})", "amit", 30);
context.query("contextSocial", "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)");
// WATCH/MULTI/EXEC
context.watch("contextSocial");
RedisGraphTransaction t = context.multi();
t.query("contextSocial", "MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b");
// support for Redis/Jedis native commands in transaction
t.set("x", "1");
t.get("x");
// get multi/exec results
List<Object> execResults = t.exec();
System.out.println(execResults.toString());

context.deleteGraph("contextSocial");
}
}
}

```
2 changes: 2 additions & 0 deletions src/main/java/com/redislabs/redisgraph/RedisGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public interface RedisGraph extends Closeable {
*/
String deleteGraph(String graphId);

@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import redis.clients.jedis.Jedis;

public interface RedisGraphContexted extends RedisGraph {
public interface RedisGraphContext extends RedisGraph {


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.redislabs.redisgraph;

public interface RedisGraphGeneralContext extends RedisGraph {
public interface RedisGraphContextGenerator extends RedisGraph {

/**
* Generate a connection bounded api
* @return a connection bounded api
*/
RedisGraphContexted getContextedAPI();
RedisGraphContext getContext();

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.redislabs.redisgraph.impl.api;

import com.redislabs.redisgraph.RedisGraphContexted;
import com.redislabs.redisgraph.RedisGraphContext;
import com.redislabs.redisgraph.ResultSet;
import com.redislabs.redisgraph.impl.Utils;
import com.redislabs.redisgraph.impl.graph_cache.RedisGraphCaches;
Expand All @@ -12,10 +12,10 @@
import java.util.List;

/**
* An implementaion of RedisGraphContexted. Allows sending RedisGraph and some Redis commands,
* An implementaion of RedisGraphContext. Allows sending RedisGraph and some Redis commands,
* within a specific connection context
*/
public class ContextedRedisGraph extends AbstractRedisGraph implements RedisGraphContexted, RedisGraphCacheHolder {
public class ContextedRedisGraph extends AbstractRedisGraph implements RedisGraphContext, RedisGraphCacheHolder {

private Jedis connectionContext;
private RedisGraphCaches caches;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.redislabs.redisgraph.impl.api;

import com.redislabs.redisgraph.RedisGraphContexted;
import com.redislabs.redisgraph.RedisGraphGeneralContext;
import com.redislabs.redisgraph.RedisGraphContext;
import com.redislabs.redisgraph.RedisGraphContextGenerator;
import com.redislabs.redisgraph.ResultSet;
import com.redislabs.redisgraph.impl.graph_cache.RedisGraphCaches;
import redis.clients.jedis.Jedis;
Expand All @@ -12,7 +12,7 @@
/**
*
*/
public class RedisGraph extends AbstractRedisGraph implements RedisGraphGeneralContext {
public class RedisGraph extends AbstractRedisGraph implements RedisGraphContextGenerator {

private final Pool<Jedis> client;
private RedisGraphCaches caches = new RedisGraphCaches();
Expand Down Expand Up @@ -99,7 +99,7 @@ public String deleteGraph(String graphId) {
* @return ContextedRedisGraph
*/
@Override
public RedisGraphContexted getContextedAPI() {
public RedisGraphContext getContext() {
ContextedRedisGraph contextedRedisGraph = new ContextedRedisGraph(getConnection());
contextedRedisGraph.setRedisGraphCaches(this.caches);
return contextedRedisGraph;
Expand Down
Loading