https://github.com/redisgraph/jredisgraph
Java API for RedisGraph
https://github.com/redisgraph/jredisgraph
cypher java-client redis redisgraph
Last synced: 8 months ago
JSON representation
Java API for RedisGraph
- Host: GitHub
- URL: https://github.com/redisgraph/jredisgraph
- Owner: RedisGraph
- License: bsd-3-clause
- Created: 2017-05-29T13:00:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-27T11:57:56.000Z (about 2 years ago)
- Last Synced: 2025-05-30T22:48:09.013Z (9 months ago)
- Topics: cypher, java-client, redis, redisgraph
- Language: Java
- Homepage: https://redisgraph.io
- Size: 927 KB
- Stars: 60
- Watchers: 6
- Forks: 20
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/RedisGraph/JRedisGraph/blob/master/LICENSE)
[](https://github.com/RedisGraph/JRedisGraph/releases/latest)
[](https://maven-badges.herokuapp.com/maven-central/com.redislabs/jredisgraph)
[](https://www.javadoc.io/doc/com.redislabs/jredisgraph)
[](https://codecov.io/gh/RedisGraph/JRedisGraph)
[](https://snyk.io/test/github/RedisGraph/JRedisGraph?targetFile=pom.xml)
# JRedisGraph
[](https://forum.redislabs.com/c/modules/redisgraph)
[](https://discord.gg/gWBRT6P)
RedisGraph Java client
## Deprecation notice
As of [Jedis](https://github.com/redis/jedis) version 4.2.0, this library is deprecated. Its features have been merged into Jedis. Please either install it from [maven](https://mvnrepository.com/artifact/redis.clients/jedis) or [the repo](https://github.com/redis/jedis).
### Official Releases
```xml
com.redislabs
jredisgraph
2.5.1
```
### Snapshots
```xml
snapshots-repo
https://oss.sonatype.org/content/repositories/snapshots
```
and
```xml
com.redislabs
jredisgraph
2.6.0-SNAPSHOT
```
## Example: Using the Java Client
```java
package com.redislabs.redisgraph;
import com.redislabs.redisgraph.graph_entities.Edge;
import com.redislabs.redisgraph.graph_entities.Node;
import com.redislabs.redisgraph.graph_entities.Path;
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();
Map params = new HashMap<>();
params.put("age", 30);
params.put("name", "amit");
// send queries to a specific graph called "social"
graph.query("social","CREATE (:person{name:'roi',age:32})");
graph.query("social","CREATE (:person{name:$name,age:$age})", params);
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());
}
resultSet = graph.query("social", "MATCH p = (:person)-[:knows]->(:person) RETURN p");
while(resultSet.hasNext()) {
Record record = resultSet.next();
Path p = record.getValue("p");
// More path API at Javadoc.
System.out.println(p.nodeCount());
}
// 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("social","CREATE (:person{name:$name,age:$age})", params);
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{name:$name,age:$age}) RETURN a, r, b", params);
// support for Redis/Jedis native commands in transaction
t.set("x", "1");
t.get("x");
// get multi/exec results
List execResults = t.exec();
System.out.println(execResults.toString());
context.deleteGraph("contextSocial");
}
}
}
```
## License
[](https://app.fossa.io/projects/git%2Bgithub.com%2FRedisGraph%2FJRedisGraph?ref=badge_large)