协调并行事务

书签是表示数据库状态的标记。当集群中的后续事务需要协调时,例如在写入数据后立即读取数据时,书签非常有用。

使用 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 驱动程序