Golang client for redislabs' ReJSON module using Redigo golang client.
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.
.github/ISSUE_TEMPLATE
examples
vendor/github.com/gomodule/redigo
.gitignore
.travis.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
README.md
install-redis-rejson.sh
rejson.go
rejson_test.go
start-redis-rejson.sh

README.md

Go-ReJSON - a golang client for ReJSON (a JSON data type for Redis)

Go-ReJSON is a Go client for rejson redis module.

Build Status codecov

ReJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating and fetching JSON values from Redis keys (documents). Primary features: > Full support of the JSON standard > JSONPath-like syntax for selecting element inside documents > Documents are stored as binary data in a tree structure, allowing fast access to sub-elements > Typed atomic operations for all JSON values types

  • Go-ReJSON is built atop the redigo client.
  • The package is intended to be used in conjuction with the redigo, which means all features provided by the original package will be available.

Installation

go get github.com/nitishm/go-rejson

Task List

Example usage

package main

import (
	"encoding/json"
	"flag"
	rejson "go-rejson"
	"log"

	"github.com/gomodule/redigo/redis"
)

var addr = flag.String("Server", "localhost:6379", "Redis server address")

type Name struct {
	First  string `json:"first,omitempty"`
	Middle string `json:"middle,omitempty"`
	Last   string `json:"last,omitempty"`
}

type Student struct {
	Name Name `json:"name,omitempty"`
	Rank int  `json:"rank,omitempty"`
}

func main() {
	flag.Parse()

	conn, err := redis.Dial("tcp", *addr)
	if err != nil {
		log.Fatalf("Failed to connect to redis-server @ %s", *addr)
	}

	student := Student{
		Name: Name{
			"Mark",
			"S",
			"Pronto",
		},
		Rank: 1,
	}
	res, err := rejson.JSONSet(conn, "student", ".", student, false, false)
	if err != nil {
		log.Fatalf("Failed to JSONSet")
		return
	}

	log.Printf("Success if - %s\n", res)

	studentJSON, err := redis.Bytes(rejson.JSONGet(conn, "student", ""))
	if err != nil {
		log.Fatalf("Failed to JSONGet")
		return
	}

	readStudent := Student{}
	err = json.Unmarshal(studentJSON, &readStudent)
	if err != nil {
		log.Fatalf("Failed to JSON Unmarshal")
		return
	}

	log.Printf("Student read from redis : %#v\n", readStudent)
}