我想用Python在RedisGraph中执行一批查询,以加快大知识图的创建。
在 Neo4J 中,Neo4J Python可以使用展开命令并允许并行查询。在这个片段中,您可以看到Python如何支持展开-- run方法将batch作为参数。batch是一个字典列表。每个字典都有head_id、tail_id和properties作为键。
with session.begin_transaction() as tx: # In this transaction relationships are inserted in the database
cypher_query = 'UNWIND $batch as row ' \
'MATCH (head:Node) WHERE head.id = row.head_id ' \
'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
'SET rel += row.properties'
tx.run(cypher_query, batch=batch)在RedisGraph中,解卷也是可用的(因为它是一个Cypher命令)。但是,我不知道如何在Python中传递一个批处理:
cypher_query = 'UNWIND $batch as row ' \
'MATCH (head:Node) WHERE head.id = row.head_id ' \
'MATCH (tail:Node) WHERE tail.id = row.tail_id ' \
'CREATE (head)-[rel:RELATIONSHIP]->(tail) ' \
'SET rel += row.properties'
r = redis.StrictRedis()
r.execute_command('GRAPH.QUERY', graph_name, cypher_query) #No batch can be passed!!你知道解决办法吗?谢谢。
发布于 2020-08-18 12:41:10
下面是RedisLabs开发团队的答案:
github.com/RedisGraph/RedisGraph/issues/1293
到目前为止,这个特性是不支持的,但将在将来引入。
https://stackoverflow.com/questions/63455736
复制相似问题