RedisGraph JavaScript Client
Installation is done using the
npm install
command:
npm install redisgraph.js
const RedisGraph = require("redisgraph.js").RedisGraph;
let graph = new RedisGraph('social');
graph
.query("CREATE (:person{name:'roi',age:32})")
.then( () => {
return graph.query("CREATE (:person{name:'amit',age:30})");
})
.then( () => {
return graph.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(a)")
})
.then( () => {
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a")
})
.then( (res) => {
while(res.hasNext()){
let record = res.next();
console.log(record.getString('a.name'));
}
console.log(res.getStatistics().queryExecutionTime());
});
const RedisGraph = require("redisgraph.js").RedisGraph;
const RedisGraphNode = require("redisgraph.js").Node;
const RedisGraphEdge = require("redisgraph.js").Edge;
let graph = new RedisGraph.RedisGraph('social');
// Create both source and destination nodes
const node1 = new RedisGraphNode(null, "a", "person",properties={
name:'roi',
age:32}
);
// Adding node1 to the graph
graph.addNode(node1);
const node2 = new RedisGraphNode(null, "b", "person",properties={
name:'amit',
age:30}
);
// Adding node2 to the graph
graph.addNode(node2);
const edge = new RedisGraphEdge(node1, "knows", node2);
// Adding edge to the graph
graph.addEdge(edge);
// Connect source and destination nodes.
graph
.commit()
.then( () => {
return graph.query("MATCH (a:person)-[:knows]->(:person) RETURN a")
})
.then( (res) => {
while(res.hasNext()){
let record = res.next();
console.log(record.getString('a.name'));
}
console.log(res.getStatistics().queryExecutionTime());
});
A simple test suite is provided, and can be run with:
$ npm test
The tests expect a Redis server with the RedisGraph module loaded to be available at localhost:6379
redisgraph.js is distributed under the BSD3 license - see LICENSE