Redis 正在逐步淘汰 RedisGraph. 这篇文章 解释了此决定的原因以及对现有 Redis 客户和社区成员的影响。
支持结束日期定为 2025 年 1 月 31 日。
RedisGraph 是最快的图数据库,它可以实时处理复杂的图操作,比任何其他图数据库快 10 倍到 600 倍。展示您的数据如何通过多个可视化集成(包括 RedisInsight、Linkurious 和 Graphileon)进行连接。使用行业标准 Cypher 查询语言查询图,并从应用程序代码中轻松使用图功能。
按照以下步骤开始使用 Java 的 RedisGraph
docker run -p 6379:6379 --name redis/redis-stack
info modules
# Modules
module:name=graph,ver=20405,api=1,filters=0,usedby=[],using=[],options=[]
git clone https://github.com/RedisGraph/redisgraph.js
npm install redisgraph.js
const RedisGraph = require('redisgraph.js').Graph;
let graph = new RedisGraph('social');
(async () => {
await graph.query("CREATE (:person{name:'roi',age:32})");
await graph.query("CREATE (:person{name:'amit',age:30})");
await graph.query(
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)",
);
// Match query.
let res = await graph.query(
'MATCH (a:person)-[:knows]->(:person) RETURN a.name',
);
while (res.hasNext()) {
let record = res.next();
console.log(record.get('a.name'));
}
console.log(res.getStatistics().queryExecutionTime());
// Match with parameters.
let param = { age: 30 };
res = await graph.query('MATCH (a {age: $age}) return a.name', param);
while (res.hasNext()) {
let record = res.next();
console.log(record.get('a.name'));
}
// Named paths matching.
res = await graph.query('MATCH p = (a:person)-[:knows]->(:person) RETURN p');
while (res.hasNext()) {
let record = res.next();
// See path.js for more path API.
console.log(record.get('p').nodeCount);
}
graph.deleteGraph();
graph.close();
})();
将以上文件保存为“app.js”。
node app.js
roi
0.1789
amit
2
1632898652.415702 [0 172.17.0.1:64144] "info"
1632898652.418225 [0 172.17.0.1:64144] "graph.query" "social" "CREATE (:person{name:'roi',age:32})" "--compact"
1632898652.420399 [0 172.17.0.1:64144] "graph.query" "social" "CREATE (:person{name:'amit',age:30})" "--compact"
1632898652.421857 [0 172.17.0.1:64144] "graph.query" "social" "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)" "--compact"
1632898652.424911 [0 172.17.0.1:64144] "graph.query" "social" "MATCH (a:person)-[:knows]->(:person) RETURN a.name" "--compact"
1632898652.429658 [0 172.17.0.1:64144] "graph.query" "social" "CYPHER age=30 MATCH (a {age: $age}) return a.name" "--compact"
1632898652.431221 [0 172.17.0.1:64144] "graph.query" "social" "MATCH p = (a:person)-[:knows]->(:person) RETURN p" "--compact"
1632898652.433146 [0 172.17.0.1:64144] "graph.query" "social" "CALL db.labels()" "--compact"
1632898652.434781 [0 172.17.0.1:64144] "graph.query" "social" "CALL db.propertyKeys()" "--compact"
1632898652.436574 [0 172.17.0.1:64144] "graph.query" "social" "CALL db.relationshipTypes()" "--compact"
1632898652.438559 [0 172.17.0.1:64144] "graph.delete" "social"
运行 RedisInsight 容器。最简单的方法是运行以下命令
docker run -d -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest
接下来,将浏览器指向 https://localhost:8001。
您可以显示查询返回的记录数量