RedisGraph / redisgraph-go

A Golang client for redisgraph
https://redisgraph.io
BSD 3-Clause "New" or "Revised" License
132 stars 38 forks source link

Clear the Nodes after commit #4

Closed maguec closed 5 years ago

maguec commented 5 years ago

Running the following

package main

import (
        "fmt"
        "github.com/gomodule/redigo/redis"
        rg "github.com/redislabs/redisgraph-go"
)

func main() {
        conn, _ := redis.Dial("tcp", "localhost:6379")
        defer conn.Close()

        graph := rg.Graph{}.New("social", conn)

        users := [3]string{"Barney", "Betty", "Bam-Bam"}

        for k, user := range users {

                family := rg.Node{
                        Label: "person",
                        Properties: map[string]interface{}{
                                "name": fmt.Sprintf("%s Rubble", user),
                                "age":  66 / (k + 2),
                        },
                }
                graph.AddNode(&family)
                graph.Commit()
        }

        query := "MATCH (p:person) RETURN p.name"
        rs, _ := graph.Query(query)

        rs.PrettyPrint()
}

Returns:

+----------------+
|     p.name     |
+----------------+
| Barney Rubble  |
| Barney Rubble  |
| Betty Rubble   |
| Barney Rubble  |
| Betty Rubble   |
| Bam-Bam Rubble |
+----------------+

Running Monitor seems to show that the node map is not being cleared after commiit

1542758947.998021 [0 127.0.0.1:61749] "GRAPH.QUERY" "social" "CREATE (BbUuWmSqQS:person{name:\"Barney Rubble\",age:33})"
1542758947.998647 [0 127.0.0.1:61749] "GRAPH.QUERY" "social" "CREATE (BbUuWmSqQS:person{name:\"Barney Rubble\",age:33}),(TfTgQICgTE:person{name:\"Betty Rubble\",age:22})"
1542758947.999356 [0 127.0.0.1:61749] "GRAPH.QUERY" "social" "CREATE (BbUuWmSqQS:person{name:\"Barney Rubble\",age:33}),(TfTgQICgTE:person{name:\"Betty Rubble\",age:22}),(nrTQwhTlDQ:person{name:\"Bam-Bam Rubble\",age:16})"
1542758947.999977 [0 127.0.0.1:61749] "GRAPH.QUERY" "social" "MATCH (p:person) RETURN p.name"
itamarhaber commented 5 years ago

Thanks @maguec - @swilly22 this is ported from redisgraph-py, WDUT?

swilly22 commented 5 years ago

The issue is with the multiple calls to graph.commit, The idea is to introduce all nodes to the graph before committing it, The example above calls commit multiple times, each time with a graph bigger by one node from the previous iteration.

swilly22 commented 5 years ago

For some use-cases it would make sense to clear after commit, but there might be situations where you would like to keep the Go graph representation, I don't mind introducing an explicit clear function but that would need to take into account both nodes and edges.

maguec commented 5 years ago

I will rewrite with a specific flush funciont