Skip to content

Commit

Permalink
Merge pull request #18 from Shivam010/master
Browse files Browse the repository at this point in the history
Suggestion for Go build version and Staticcheck and Commands Added
  • Loading branch information
nitishm authored Jan 5, 2019
2 parents 5435bd1 + 44f06d8 commit 76806f6
Show file tree
Hide file tree
Showing 6 changed files with 665 additions and 62 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: go
go:
- 1.9.x
- 1.10.x
- tip
- 1.11.x

matrix:
allow_failures:
Expand All @@ -18,6 +17,7 @@ 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

Expand All @@ -28,7 +28,8 @@ script:
- go test -v .
- go test -covermode=count -coverprofile=profile.cov .
- go vet -x .
- staticcheck .

after_script:
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Go-ReJSON is a [Go](https://golang.org/) client for [rejson](https://github.com/
- [x] [JSON.ARRPOP](http://rejson.io/commands/#jsonarrpop)
- [x] [JSON.ARRTRIM](http://rejson.io/commands/#jsonarrtrim)
- [x] [JSON.ARRINSERT](http://rejson.io/commands/#jsonarrinsert)
- [ ] [JSON.OBJKEYS](http://rejson.io/commands/#jsonobjkeys)
- [ ] [JSON.OBJLEN](http://rejson.io/commands/#jsonobjlen)
- [ ] [JSON.DEBUG](http://rejson.io/commands/#jsondebug)
- [ ] [JSON.FORGET](http://rejson.io/commands/#jsonforget)
- [ ] [JSON.RESP](http://rejson.io/commands/#jsonresp)
- [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
Expand Down
93 changes: 93 additions & 0 deletions examples/json_obj.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/nitishm/go-rejson"
"log"
)

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

flag.Parse()

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

type Object struct {
Name string `json:"name"`
LastSeen int64 `json:"lastSeen"`
LoggedOut bool `json:"loggedOut"`
}

obj := Object{"Leonard Cohen", 1478476800, true}
res, err := rejson.JSONSet(conn, "obj", ".", obj, false, false)
if err != nil {
log.Fatalf("Failed to JSONSet")
return
}
fmt.Println("obj:", res)

res, err = rejson.JSONGet(conn, "obj", ".")
if err != nil {
log.Fatalf("Failed to JSONGet")
return
}
var objOut Object
err = json.Unmarshal(res.([]byte), &objOut)
if err != nil {
log.Fatalf("Failed to JSON Unmarshal")
return
}
fmt.Println("got obj:", objOut)

res, err = rejson.JSONObjLen(conn, "obj", ".")
if err != nil {
log.Fatalf("Failed to JSONObjLen")
return
}
fmt.Println("length:", res)

res, err = rejson.JSONObjKeys(conn, "obj", ".")
if err != nil {
log.Fatalf("Failed to JSONObjKeys")
return
}
fmt.Println("keys:", res)

res, err = rejson.JSONDebug(conn, rejson.DebugHelpSubcommand, "obj", ".")
if err != nil {
log.Fatalf("Failed to JSONDebug")
return
}
fmt.Println(res)
res, err = rejson.JSONDebug(conn, rejson.DebugMemorySubcommand, "obj", ".")
if err != nil {
log.Fatalf("Failed to JSONDebug")
return
}
fmt.Println("Memory used by obj:", res)

res, err = rejson.JSONGet(conn, "obj", ".",
&rejson.JSONGetOptionIndent{"\t"}, &rejson.JSONGetOptionNewLine{"\n"},
&rejson.JSONGetOptionSpace{" "}, &rejson.JSONGetOptionNoEscape{})
if err != nil {
log.Fatalf("Failed to JSONGet")
return
}
err = json.Unmarshal(res.([]byte), &objOut)
if err != nil {
log.Fatalf("Failed to JSON Unmarshal")
return
}
fmt.Println("got obj with options:", objOut)
}
Loading

0 comments on commit 76806f6

Please sign in to comment.