redisgraph

package module
v1.99.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: BSD-3-Clause Imports: 9 Imported by: 0

README

license CircleCI GitHub issues Codecov Go Report Card GoDoc

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"
    rg "github.com/redislabs/redisgraph-go"
)

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

    graph := rg.GraphNew("social", conn)

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

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

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

    graph.Commit()

    query := `MATCH (p:person)-[v:visited]->(c:country)
           RETURN p.name, p.age, v.purpose, c.name`
    rs, _ := graph.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

View Source
const (
	LABELS_ADDED            string = "Labels added"
	NODES_CREATED           string = "Nodes created"
	NODES_DELETED           string = "Nodes deleted"
	RELATIONSHIPS_DELETED   string = "Relationships deleted"
	PROPERTIES_SET          string = "Properties set"
	RELATIONSHIPS_CREATED   string = "Relationships created"
	INTERNAL_EXECUTION_TIME string = "internal execution time"
)

Variables

This section is empty.

Functions

func ToString added in v1.99.3

func ToString(i interface{}) interface{}

Types

type Edge

type Edge struct {
	ID          uint64
	Relation    string
	Source      *Node
	Destination *Node
	Properties  map[string]interface{}
	// contains filtered or unexported fields
}

Edge represents an edge connecting two nodes in the graph.

func EdgeNew added in v1.99.3

func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[string]interface{}) *Edge

func (Edge) DestNodeID added in v1.99.3

func (e Edge) DestNodeID() uint64

func (Edge) Encode added in v1.99.3

func (e Edge) Encode() string

func (*Edge) GetProperty added in v1.99.3

func (e *Edge) GetProperty(key string) interface{}

func (*Edge) SetProperty added in v1.99.3

func (e *Edge) SetProperty(key string, value interface{})

func (Edge) SourceNodeID added in v1.99.3

func (e Edge) SourceNodeID() uint64

func (Edge) String

func (e Edge) String() string

type Graph

type Graph struct {
	Id    string
	Nodes map[string]*Node
	Edges []*Edge
	Conn  redis.Conn
	// contains filtered or unexported fields
}

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

func GraphNew added in v1.99.3

func GraphNew(Id string, conn redis.Conn) Graph

New creates a new graph.

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)

AddNode adds a node to the graph.

func (*Graph) CallProcedure added in v1.99.3

func (g *Graph) CallProcedure(procedure string, yield []string, args ...interface{}) (*QueryResult, error)

CallProcedure invokes procedure.

func (*Graph) Commit

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

Commit creates the entire graph, but will re-add nodes if called again.

func (*Graph) Delete

func (g *Graph) Delete() error

Delete removes the graph.

func (*Graph) ExecutionPlan

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

ExecutionPlan gets the execution plan for given query.

func (*Graph) Flush added in v1.99.3

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

Flush will create the graph and clear it

func (*Graph) Labels added in v1.99.3

func (g *Graph) Labels() []string

Labels, retrieves all node labels.

func (*Graph) Merge added in v1.99.3

func (g *Graph) Merge(p string) (*QueryResult, error)

Merge pattern

func (*Graph) PropertyKeys added in v1.99.3

func (g *Graph) PropertyKeys() []string

PropertyKeys, retrieves all properties names.

func (*Graph) Query

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

Query executes a query against the graph.

func (*Graph) RelationshipTypes added in v1.99.3

func (g *Graph) RelationshipTypes() []string

RelationshipTypes, retrieves all edge relationship types.

type Node

type Node struct {
	ID         uint64
	Label      string
	Alias      string
	Properties map[string]interface{}
	// contains filtered or unexported fields
}

Node represents a node within a graph.

func NodeNew added in v1.99.3

func NodeNew(label string, alias string, properties map[string]interface{}) *Node

func (Node) Encode added in v1.99.3

func (n Node) Encode() string

String makes Node satisfy the Stringer interface.

func (Node) GetProperty added in v1.99.3

func (n Node) GetProperty(key string) interface{}

func (*Node) SetProperty added in v1.99.3

func (n *Node) SetProperty(key string, value interface{})

func (Node) String

func (n Node) String() string

type QueryResult

type QueryResult struct {
	Results    [][]interface{}
	Statistics map[string]float64
	Header     QueryResultHeader
	// contains filtered or unexported fields
}

QueryResult represents the Results of a query.

func QueryResultNew added in v1.99.3

func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error)

func (*QueryResult) Empty added in v1.99.3

func (qr *QueryResult) Empty() bool

func (*QueryResult) LabelsAdded added in v1.99.3

func (qr *QueryResult) LabelsAdded() int

func (*QueryResult) NodesCreated added in v1.99.3

func (qr *QueryResult) NodesCreated() int

func (*QueryResult) NodesDeleted added in v1.99.3

func (qr *QueryResult) NodesDeleted() int

func (*QueryResult) PrettyPrint

func (qr *QueryResult) PrettyPrint()

PrettyPrint prints the QueryResult to stdout, pretty-like.

func (*QueryResult) PropertiesSet added in v1.99.3

func (qr *QueryResult) PropertiesSet() int

func (*QueryResult) RelationshipsCreated added in v1.99.3

func (qr *QueryResult) RelationshipsCreated() int

func (*QueryResult) RelationshipsDeleted added in v1.99.3

func (qr *QueryResult) RelationshipsDeleted() int

func (*QueryResult) RunTime added in v1.99.3

func (qr *QueryResult) RunTime() int

type QueryResultHeader added in v1.99.3

type QueryResultHeader struct {
	ColumnNames []string
	ColumnTypes []ResultSetColumnTypes
}

type ResultSetColumnTypes added in v1.99.3

type ResultSetColumnTypes int
const (
	COLUMN_UNKNOWN ResultSetColumnTypes = iota
	COLUMN_SCALAR
	COLUMN_NODE
	COLUMN_RELATION
)

type ResultSetScalarTypes added in v1.99.3

type ResultSetScalarTypes int
const (
	VALUE_UNKNOWN ResultSetScalarTypes = iota
	VALUE_NULL
	VALUE_STRING
	VALUE_INTEGER
	VALUE_BOOLEAN
	VALUE_DOUBLE
	VALUE_ARRAY
	VALUE_EDGE
	VALUE_NODE
)

Jump to

Keyboard shortcuts

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