协调并行事务
书签是表示数据库状态的标记。当集群中的后续事务需要协调时,书签很有用,例如当您需要在写入数据后立即读取数据时。
使用 GDS 客户端时,在调用 gds.set_bookmarks()
之后的所有查询都不会执行,直到将已加书签的事务传播到整个集群。
使用 GDS 的书签示例
# Use the `bookmarks` parameter to set any existing bookmarks, for example
# after running a query through the Neo4j driver. The default value is `None`.
gds = GraphDataScience(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD), bookmarks=None)
gds.run_cypher("""
CREATE (:Person {name: "Alice"})-[:KNOWS]->(:Person {name: "Bob"})
""")
# Make sure the next queries will be executed after the CREATE query is fully propagated through the cluster
gds.set_bookmarks(gds.last_bookmarks())
G, _ = gds.graph.project("myGraph", "Person", "KNOWS")
gds.pageRank.write(G, writeProperty="pagerank")
# Make sure the next queries will be executed after the pageRank scores were written back to the cluster
gds.set_bookmarks(gds.last_bookmarks())
result = gds.run_cypher("MATCH (p:Person) RETURN p.name, p.pagerank")
G.drop()
有关书签的更多详细信息,请参阅Neo4j Python 驱动程序。