redisgraph

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	Source      *Node
	Destination *Node
	Relation    string
	Properties  map[string]interface{}
}

Edge represents an edge connecting two nodes in the graph.

func (*Edge) String

func (e *Edge) String() string

type Graph

type Graph struct {
	Name  string
	Nodes map[string]*Node
	Edges []*Edge
	Conn  redis.Conn
}

Graph represents a graph, which is a collection of nodes and edges.

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge) error

AddEdge adds an edge to the graph.

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node) error

AddNode adds a node to the graph.

func (*Graph) Commit

func (g *Graph) Commit() (QueryResult, error)

Commit creates the entire graph.

func (*Graph) Delete

func (g *Graph) Delete() error

func (*Graph) ExecutionPlan

func (g *Graph) ExecutionPlan(q string) (string, error)

ExecutionPlan gets the execution plan for given query.

func (Graph) New

func (g Graph) New(name string, conn redis.Conn) Graph

New creates a new graph.

func (*Graph) Query

func (g *Graph) Query(q string) (QueryResult, error)

Query executes a query against the graph.

type Node

type Node struct {
	ID         string
	Alias      string
	Label      string
	Properties map[string]interface{}
}

Node represents a node within a graph.

func (*Node) String

func (n *Node) String() string

type QueryResult

type QueryResult struct {
	Results    [][]string
	Statistics []string
}

QueryResult represents the results of a query.

func (*QueryResult) PrettyPrint

func (qr *QueryResult) PrettyPrint()

PrettyPrint prints the QueryResult to stdout, pretty-like.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL