-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Shivam010/master
Suggestion for Go build version and Staticcheck and Commands Added
- Loading branch information
Showing
6 changed files
with
665 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.