Search code examples
redisredisgraph

How to prevent data duplication in redisgraph?


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?


Solution

  • If your code consists of a series of CREATE commands (whether through Cypher or one of the RedisGraph clients), running it twice will duplicate all of your data. This is not to say that the key stores two graphs; rather, it is one graph with every entity repeated.

    If you would like to replace an existing graph, you should delete the existing graph first. You can delete a graph using a Redis command:

    DEL [graph key]

    Or a RedisGraph command:

    GRAPH.DELETE [graph key]

    The two are functionally identical.

    Conversely, if you want to update an existing graph without introducing duplicates, you should use the MERGE clause as described in the RedisGraph documentation.