5656```
5757
5858# Example: Using the Java Client
59-
59+ ## Up to 2.0.0
6060``` java
6161package com.redislabs.redisgraph ;
6262
@@ -80,3 +80,59 @@ public class RedisGraphExample {
8080}
8181
8282```
83+ ## From 2.0.0
84+
85+ ``` java
86+ package com.redislabs.redisgraph ;
87+
88+ import com.redislabs.redisgraph.graph_entities.Edge ;
89+ import com.redislabs.redisgraph.graph_entities.Node ;
90+ import com.redislabs.redisgraph.impl.api.RedisGraph ;
91+
92+ import java.util.List ;
93+
94+ public class RedisGraphExample {
95+ public static void main (String [] args ) {
96+ // general context api. Not bound to graph key or connection
97+ RedisGraphGeneralContext api = new RedisGraph ();
98+
99+ // send queries to a specific graph called "social"
100+ api. query(" social" ," CREATE (:person{name:'roi',age:32})" );
101+ api. query(" social" ," CREATE (:person{name:%s,age:%d})" , " amit" , 30 );
102+ api. query(" social" ," MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)" );
103+
104+ ResultSet resultSet = api. query(" social" , " MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b" );
105+ while (resultSet. hasNext()) {
106+ Record record = resultSet. next();
107+ // get values
108+ Node a = record. getValue(" a" );
109+ Edge r = record. getValue(" r" );
110+
111+ // print record
112+ System . out. println(record. toString());
113+ }
114+
115+ // delete graph
116+ api. deleteGraph(" social" );
117+
118+ // get connection context
119+ RedisGraphContexted contextApi = api. getContextedAPI();
120+ contextApi. query(" contextSocial" ," CREATE (:person{name:'roi',age:32})" );
121+ contextApi. query(" contextSocial" ," CREATE (:person{name:%s,age:%d})" , " amit" , 30 );
122+ contextApi. query(" contextSocial" , " MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)" );
123+ // WATCH/MULTI/EXEC
124+ contextApi. watch(" contextSocial" );
125+ RedisGraphTransaction t = contextApi. multi();
126+ t. query(" contextSocial" , " MATCH (a:person)-[r:knows]->(b:person) RETURN a, r, b" );
127+ // support for Redis/Jedis native commands in transaction
128+ t. set(" x" , " 1" );
129+ t. get(" x" );
130+ // get multi/exec results
131+ List<Object > execResults = t. exec();
132+ System . out. println(execResults. toString());
133+
134+ contextApi. deleteGraph(" contextSocial" );
135+ }
136+ }
137+
138+ ```
0 commit comments