Skip to content

Commit 9b731b1

Browse files
authored
Merge pull request #29 from Shivam010/v2
Support for various clients - #27
2 parents 80d4d70 + c4b831a commit 9b731b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+13508
-1009
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters-settings:
1818
linters:
1919
enable-all: true
2020
disable:
21+
- goimports
2122
- scopelint
2223
- gochecknoglobals
2324
- dupl

.travis.yml

-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go:
44
- 1.11.x
55

66
matrix:
7-
allow_failures:
8-
- go: tip
97
fast_finish: true
108

119
services:
@@ -17,7 +15,6 @@ before_install:
1715
- docker ps -a
1816
- curl -L -s https://github.com/golang/dep/releases/download/v0.3.1/dep-linux-amd64 -o $GOPATH/bin/dep
1917
- chmod +x $GOPATH/bin/dep
20-
- go get honnef.co/go/tools/cmd/staticcheck
2118
- go get golang.org/x/tools/cmd/cover
2219
- go get github.com/mattn/goveralls
2320
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.12.5

Gopkg.lock

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gopkg.toml example
22
#
3-
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
44
# for detailed Gopkg.toml documentation.
55
#
66
# required = ["github.com/user/thing/cmd/thing"]
@@ -25,14 +25,14 @@
2525
# unused-packages = true
2626

2727

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

3232
[[constraint]]
3333
name = "github.com/gomodule/redigo"
3434
version = "2.0.0"
3535

36-
[[constraint]]
37-
name = "github.com/rafaeljusto/redigomock"
38-
version = "2.1.0"
36+
[prune]
37+
go-tests = true
38+
unused-packages = true

README.md

+67-44
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,60 @@
11
# Go-ReJSON - a golang client for ReJSON (a JSON data type for Redis)
2-
Go-ReJSON is a [Go](https://golang.org/) client for [rejson](https://github.com/RedisLabsModules/rejson) redis module.
2+
Go-ReJSON is a [Go](https://golang.org/) client for [ReJSON](https://github.com/RedisLabsModules/rejson) Redis Module.
33

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

99
> 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).
10-
> Primary features:
11-
> Full support of the JSON standard
12-
> JSONPath-like syntax for selecting element inside documents
13-
> Documents are stored as binary data in a tree structure, allowing fast access to sub-elements
14-
> Typed atomic operations for all JSON values types
15-
- Go-ReJSON is built atop the [redigo](https://github.com/gomodule/redigo) client.
16-
- 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.
10+
11+
12+
Primary features of ReJSON Module:
13+
14+
* Full support of the JSON standard
15+
* JSONPath-like syntax for selecting element inside documents
16+
* Documents are stored as binary data in a tree structure, allowing fast access to sub-elements
17+
* Typed atomic operations for all JSON values types
18+
19+
Each and every feature of ReJSON Module is fully incorporated in the project.
20+
21+
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).
22+
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.
23+
24+
Support for `mediocregopher/radix` and other Redis clients is in our RoadMap. Any contributions on the support for other clients is hearty welcome.
1725

1826
## Installation
1927
go get github.com/nitishm/go-rejson
2028

21-
## Task List
22-
- [x] [JSON.SET](http://rejson.io/commands/#jsondel)
23-
- [x] [JSON.GET](http://rejson.io/commands/#jsonget)
24-
- [x] [JSON.MGET](http://rejson.io/commands/#jsonmget)
25-
- [x] [JSON.DEL](http://rejson.io/commands/#jsondel)
26-
- [x] [JSON.TYPE](http://rejson.io/commands/#jsontype)
27-
- [x] [JSON.NUMINCBY](http://rejson.io/commands/#jsonnumincrby)
28-
- [x] [JSON.NUMMULTBY](http://rejson.io/commands/#jsonnummultby)
29-
- [x] [JSON.STRAPPEND](http://rejson.io/commands/#jsonstrappend)
30-
- [x] [JSON.STRLEN](http://rejson.io/commands/#jsonstrlen)
31-
- [x] [JSON.ARRAPPEND](http://rejson.io/commands/#jsonarrappend)
32-
- [x] [JSON.ARRLEN](http://rejson.io/commands/#jsonarrlen)
33-
- [x] [JSON.ARRINDEX](http://rejson.io/commands/#jsonarrindex)
34-
- [x] [JSON.ARRPOP](http://rejson.io/commands/#jsonarrpop)
35-
- [x] [JSON.ARRTRIM](http://rejson.io/commands/#jsonarrtrim)
36-
- [x] [JSON.ARRINSERT](http://rejson.io/commands/#jsonarrinsert)
37-
- [x] [JSON.OBJKEYS](http://rejson.io/commands/#jsonobjkeys)
38-
- [x] [JSON.OBJLEN](http://rejson.io/commands/#jsonobjlen)
39-
- [x] [JSON.DEBUG](http://rejson.io/commands/#jsondebug)
40-
- [x] [JSON.FORGET](http://rejson.io/commands/#jsonforget)
41-
- [x] [JSON.RESP](http://rejson.io/commands/#jsonresp)
42-
4329
## Example usage
4430
```golang
4531
package main
4632

4733
import (
4834
"encoding/json"
4935
"flag"
50-
rejson "go-rejson"
36+
"fmt"
5137
"log"
5238

39+
"github.com/nitishm/go-rejson"
40+
goredis "github.com/go-redis/redis"
5341
"github.com/gomodule/redigo/redis"
5442
)
5543

56-
var addr = flag.String("Server", "localhost:6379", "Redis server address")
57-
44+
// Name - student name
5845
type Name struct {
5946
First string `json:"first,omitempty"`
6047
Middle string `json:"middle,omitempty"`
6148
Last string `json:"last,omitempty"`
6249
}
6350

51+
// Student - student object
6452
type Student struct {
6553
Name Name `json:"name,omitempty"`
6654
Rank int `json:"rank,omitempty"`
6755
}
6856

69-
func main() {
70-
flag.Parse()
71-
72-
conn, err := redis.Dial("tcp", *addr)
73-
if err != nil {
74-
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
75-
}
57+
func Example_JSONSet(rh *rejson.Handler) {
7658

7759
student := Student{
7860
Name: Name{
@@ -82,15 +64,19 @@ func main() {
8264
},
8365
Rank: 1,
8466
}
85-
res, err := rejson.JSONSet(conn, "student", ".", student, false, false)
67+
res, err := rh.JSONSet("student", ".", student)
8668
if err != nil {
8769
log.Fatalf("Failed to JSONSet")
8870
return
8971
}
9072

91-
log.Printf("Success if - %s\n", res)
73+
if res.(string) == "OK" {
74+
fmt.Printf("Success: %s\n", res)
75+
} else {
76+
fmt.Println("Failed to Set: ")
77+
}
9278

93-
studentJSON, err := redis.Bytes(rejson.JSONGet(conn, "student", ""))
79+
studentJSON, err := redis.Bytes(rh.JSONGet("student", "."))
9480
if err != nil {
9581
log.Fatalf("Failed to JSONGet")
9682
return
@@ -103,6 +89,43 @@ func main() {
10389
return
10490
}
10591

106-
log.Printf("Student read from redis : %#v\n", readStudent)
92+
fmt.Printf("Student read from redis : %#v\n", readStudent)
93+
}
94+
95+
func main() {
96+
var addr = flag.String("Server", "localhost:6379", "Redis server address")
97+
98+
rh := rejson.NewReJSONHandler()
99+
flag.Parse()
100+
101+
// Redigo Client
102+
conn, err := redis.Dial("tcp", *addr)
103+
if err != nil {
104+
log.Fatalf("Failed to connect to redis-server @ %s", *addr)
105+
}
106+
defer func() {
107+
_, err = conn.Do("FLUSHALL")
108+
err = conn.Close()
109+
if err != nil {
110+
log.Fatalf("Failed to communicate to redis-server @ %v", err)
111+
}
112+
}()
113+
rh.SetRedigoClient(conn)
114+
fmt.Println("Executing Example_JSONSET for Redigo Client")
115+
Example_JSONSet(rh)
116+
117+
// GoRedis Client
118+
cli := goredis.NewClient(&goredis.Options{Addr: *addr})
119+
defer func() {
120+
if err := cli.FlushAll().Err(); err != nil {
121+
log.Fatalf("goredis - failed to flush: %v", err)
122+
}
123+
if err := cli.Close(); err != nil {
124+
log.Fatalf("goredis - failed to communicate to redis-server: %v", err)
125+
}
126+
}()
127+
rh.SetGoRedisClient(cli)
128+
fmt.Println("\nExecuting Example_JSONSET for Redigo Client")
129+
Example_JSONSet(rh)
107130
}
108131
```

0 commit comments

Comments
 (0)