-
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.
- Loading branch information
Showing
4 changed files
with
225 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
debug.test | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# IDE Preferences | ||
.idea/ | ||
.vscode/ | ||
.vs/ |
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,86 @@ | ||
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() | ||
}() | ||
|
||
ArrIn := []string{"one", "two", "three", "four", "five"} | ||
res, err := rejson.JSONSet(conn, "arr", ".", ArrIn, false, false) | ||
if err != nil { | ||
log.Fatalf("Failed to JSONSet") | ||
return | ||
} | ||
fmt.Println("arr:", res) | ||
|
||
res, err = rejson.JSONGet(conn, "arr", ".") | ||
if err != nil { | ||
log.Fatalf("Failed to JSONGet") | ||
return | ||
} | ||
var ArrOut []string | ||
err = json.Unmarshal(res.([]byte), &ArrOut) | ||
if err != nil { | ||
log.Fatalf("Failed to JSON Unmarshal") | ||
return | ||
} | ||
fmt.Println("arr before pop:", ArrOut) | ||
|
||
res, err = rejson.JSONArrLen(conn, "arr", ".") | ||
if err != nil { | ||
log.Fatalf("Failed to JSONArrLen") | ||
return | ||
} | ||
fmt.Println("Length:", res) | ||
|
||
res, err = rejson.JSONArrPop(conn, "arr", ".", rejson.PopArrLast) | ||
if err != nil { | ||
log.Fatalf("Failed to JSONArrLen") | ||
return | ||
} | ||
var ele string | ||
err = json.Unmarshal(res.([]byte), &ele) | ||
if err != nil { | ||
log.Fatalf("Failed to JSON Unmarshal") | ||
return | ||
} | ||
fmt.Println("Deleted element:", ele) | ||
|
||
res, err = rejson.JSONGet(conn, "arr", ".") | ||
if err != nil { | ||
log.Fatalf("Failed to JSONGet") | ||
return | ||
} | ||
err = json.Unmarshal(res.([]byte), &ArrOut) | ||
if err != nil { | ||
log.Fatalf("Failed to JSON Unmarshal") | ||
return | ||
} | ||
fmt.Println("arr after pop:", ArrOut) | ||
|
||
res, err = rejson.JSONArrLen(conn, "arr", ".") | ||
if err != nil { | ||
log.Fatalf("Failed to JSONArrLen") | ||
return | ||
} | ||
fmt.Println("Length:", res) | ||
|
||
} |
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