1

I wrote one code to store graph in redisgraph. Initially it is storing single graph but if I execute the same code second time then it is storing the same graph in database without replacing the previous graph.So, now I am getting two same graphs in a single key in the database.I don't want any duplicate graph or any duplicate node that means if I execute same code again it should replace previous graph.How will I do that?

4

3 回答 3

4

如果您的代码包含一系列 CREATE 命令(无论是通过 Cypher 还是通过其中一个 RedisGraph 客户端),那么运行它两次将复制您的所有数据。这并不是说 key 存储两个图;相反,它是一个每个实体都重复的图。

如果要替换现有图表,应先删除现有图表。您可以使用 Redis 命令删除图形:

DEL [graph key]

或 RedisGraph 命令:

GRAPH.DELETE [graph key]

两者在功能上是相同的。

相反,如果您想在不引入重复项的情况下更新现有图,则应使用RedisGraph 文档中描述的 MERGE 子句。

于 2020-05-22T19:10:48.137 回答
0

您可以使用 MERGE 子句来防止插入重复数据。

下面是从现有数据中删除重复记录的查询

MATCH (p:LabelName)
WITH p.id as id, collect(p) AS nodes 
WHERE size(nodes) >  1
UNWIND nodes[1..] AS node
DELETE node
于 2020-06-16T02:33:56.240 回答
0

MERGE会像find 或 create一样。如果您的节点、边或路径不存在,它将创建它。

如果不允许重复实体,这是避免重复实体的推荐方法。

于 2021-07-10T15:24:50.063 回答