Skip to content

Commit

Permalink
Merge pull request #29 from Shivam010/v2
Browse files Browse the repository at this point in the history
Support for various clients - #27
  • Loading branch information
nitishm authored Jan 27, 2019
2 parents 80d4d70 + c4b831a commit 9b731b1
Show file tree
Hide file tree
Showing 58 changed files with 13,508 additions and 1,009 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ linters-settings:
linters:
enable-all: true
disable:
- goimports
- scopelint
- gochecknoglobals
- dupl
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ go:
- 1.11.x

matrix:
allow_failures:
- go: tip
fast_finish: true

services:
Expand All @@ -17,7 +15,6 @@ before_install:
- docker ps -a
- curl -L -s https://github.com/golang/dep/releases/download/v0.3.1/dep-linux-amd64 -o $GOPATH/bin/dep
- chmod +x $GOPATH/bin/dep
- go get honnef.co/go/tools/cmd/staticcheck
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.12.5
Expand Down
25 changes: 23 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
Expand All @@ -25,14 +25,14 @@
# unused-packages = true


[prune]
go-tests = true
unused-packages = true
[[constraint]]
name = "github.com/go-redis/redis"
version = "6.15.1"

[[constraint]]
name = "github.com/gomodule/redigo"
version = "2.0.0"

[[constraint]]
name = "github.com/rafaeljusto/redigomock"
version = "2.1.0"
[prune]
go-tests = true
unused-packages = true
111 changes: 67 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,60 @@
# Go-ReJSON - a golang client for ReJSON (a JSON data type for Redis)
Go-ReJSON is a [Go](https://golang.org/) client for [rejson](https://github.com/RedisLabsModules/rejson) redis module.
Go-ReJSON is a [Go](https://golang.org/) client for [ReJSON](https://github.com/RedisLabsModules/rejson) Redis Module.

[![GoDoc](https://godoc.org/github.com/nitishm/go-rejson?status.svg)](https://godoc.org/github.com/nitishm/go-rejson)
[![Build Status](https://travis-ci.org/nitishm/go-rejson.svg?branch=master)](https://travis-ci.org/nitishm/go-rejson)
[![codecov](https://coveralls.io/repos/github/nitishm/go-rejson/badge.svg?branch=master)](https://coveralls.io/github/nitishm/go-rejson?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/nitishm/go-rejson)](https://goreportcard.com/report/github.com/nitishm/go-rejson)

> 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](https://github.com/gomodule/redigo) client.
- The package is intended to be used in conjuction with the [redigo](https://github.com/gomodule/redigo), which means all features provided by the original package will be available.

Primary features of ReJSON Module:

* 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

Each and every feature of ReJSON Module is fully incorporated in the project.

Enjoy ReJSON with the type-safe Redis client, [`Go-Redis/Redis`](https://github.com/go-redis/redis) or use the print-like Redis-api client [`GoModule/Redigo`](https://github.com/gomodule/redigo/redis).
Go-ReJSON supports both the clients. Use any of the above two client you want, Go-ReJSON helps you out with all its features and functionalities in a more generic and standard way.

Support for `mediocregopher/radix` and other Redis clients is in our RoadMap. Any contributions on the support for other clients is hearty welcome.

## Installation
go get github.com/nitishm/go-rejson

## Task List
- [x] [JSON.SET](http://rejson.io/commands/#jsondel)
- [x] [JSON.GET](http://rejson.io/commands/#jsonget)
- [x] [JSON.MGET](http://rejson.io/commands/#jsonmget)
- [x] [JSON.DEL](http://rejson.io/commands/#jsondel)
- [x] [JSON.TYPE](http://rejson.io/commands/#jsontype)
- [x] [JSON.NUMINCBY](http://rejson.io/commands/#jsonnumincrby)
- [x] [JSON.NUMMULTBY](http://rejson.io/commands/#jsonnummultby)
- [x] [JSON.STRAPPEND](http://rejson.io/commands/#jsonstrappend)
- [x] [JSON.STRLEN](http://rejson.io/commands/#jsonstrlen)
- [x] [JSON.ARRAPPEND](http://rejson.io/commands/#jsonarrappend)
- [x] [JSON.ARRLEN](http://rejson.io/commands/#jsonarrlen)
- [x] [JSON.ARRINDEX](http://rejson.io/commands/#jsonarrindex)
- [x] [JSON.ARRPOP](http://rejson.io/commands/#jsonarrpop)
- [x] [JSON.ARRTRIM](http://rejson.io/commands/#jsonarrtrim)
- [x] [JSON.ARRINSERT](http://rejson.io/commands/#jsonarrinsert)
- [x] [JSON.OBJKEYS](http://rejson.io/commands/#jsonobjkeys)
- [x] [JSON.OBJLEN](http://rejson.io/commands/#jsonobjlen)
- [x] [JSON.DEBUG](http://rejson.io/commands/#jsondebug)
- [x] [JSON.FORGET](http://rejson.io/commands/#jsonforget)
- [x] [JSON.RESP](http://rejson.io/commands/#jsonresp)

## Example usage
```golang
package main

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

"github.com/nitishm/go-rejson"
goredis "github.com/go-redis/redis"
"github.com/gomodule/redigo/redis"
)

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

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

// Student - student object
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)
}
func Example_JSONSet(rh *rejson.Handler) {

student := Student{
Name: Name{
Expand All @@ -82,15 +64,19 @@ func main() {
},
Rank: 1,
}
res, err := rejson.JSONSet(conn, "student", ".", student, false, false)
res, err := rh.JSONSet("student", ".", student)
if err != nil {
log.Fatalf("Failed to JSONSet")
return
}

log.Printf("Success if - %s\n", res)
if res.(string) == "OK" {
fmt.Printf("Success: %s\n", res)
} else {
fmt.Println("Failed to Set: ")
}

studentJSON, err := redis.Bytes(rejson.JSONGet(conn, "student", ""))
studentJSON, err := redis.Bytes(rh.JSONGet("student", "."))
if err != nil {
log.Fatalf("Failed to JSONGet")
return
Expand All @@ -103,6 +89,43 @@ func main() {
return
}

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

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

rh := rejson.NewReJSONHandler()
flag.Parse()

// Redigo Client
conn, err := redis.Dial("tcp", *addr)
if err != nil {
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
}
defer func() {
_, err = conn.Do("FLUSHALL")
err = conn.Close()
if err != nil {
log.Fatalf("Failed to communicate to redis-server @ %v", err)
}
}()
rh.SetRedigoClient(conn)
fmt.Println("Executing Example_JSONSET for Redigo Client")
Example_JSONSet(rh)

// GoRedis Client
cli := goredis.NewClient(&goredis.Options{Addr: *addr})
defer func() {
if err := cli.FlushAll().Err(); err != nil {
log.Fatalf("goredis - failed to flush: %v", err)
}
if err := cli.Close(); err != nil {
log.Fatalf("goredis - failed to communicate to redis-server: %v", err)
}
}()
rh.SetGoRedisClient(cli)
fmt.Println("\nExecuting Example_JSONSET for Redigo Client")
Example_JSONSet(rh)
}
```
Loading

0 comments on commit 9b731b1

Please sign in to comment.