A Golang client for redisgraph
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
client.go
client_test.go

README.md

redisgraph-go

redisgraph-go is a Golang client for the RedisGraph module. It relies on redigo for Redis connection management and provides support for RedisGraph's QUERY, EXPLAIN, and DELETE commands.

Installation

Simply do:

$ go get github.com/redislabs/redisgraph-go

Usage

package main

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

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

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

	john := Node{
		Label: "person",
		Properties: map[string]interface{}{
			"name":   "John Doe",
			"age":    33,
			"gender": "male",
			"status": "single",
		},
	}
	rg.AddNode(&john)

	japan := Node{
		Label: "country",
		Properties: map[string]interface{}{
			"name": "Japan",
		},
	}
	rg.AddNode(&japan)

	edge := Edge{
		Source:      &john,
		Relation:    "visited",
		Destination: &japan,
	}
	rg.AddEdge(&edge)

	rg.Commit()

	query := `MATCH (p:person)-[v:visited]->(c:country)
		   RETURN p.name, p.age, v.purpose, c.name`
	rs, _ := rg.Query(query)

	rs.PrettyPrint()
}

Running the above should output:

$ go run main.go
+----------+-----------+-----------+--------+
|  p.name  |   p.age   | v.purpose | c.name |
+----------+-----------+-----------+--------+
| John Doe | 33.000000 | NULL      | Japan  |
+----------+-----------+-----------+--------+

Running tests

A simple test suite is provided, and can be run with:

$ go test

The tests expect a Redis server with the RedisGraph module loaded to be available at localhost:6379

License

redisgraph-go is distributed under the BSD3 license - see LICENSE