模块
github地址 : https://github.com/nitishm/go-rejson
json
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package main
import ( "encoding/json" "fmt" "log"
goredis "github.com/go-redis/redis"
"github.com/gomodule/redigo/redis" "github.com/nitishm/go-rejson" )
func main() { rh := rejson.NewReJSONHandler() conn, err := redis.Dial("tcp", "192.168.1.131:6379") if err != nil { return } rh.SetRedigoClient(conn) js1, err := redis.Bytes(rh.JSONGet("group", ".")) if err != nil { log.Fatalf("Failed to JSONGet") return } var group interface{} err = json.Unmarshal(js1, &group) if err != nil { return } fmt.Println("group1") fmt.Println(group) js1, err = redis.Bytes(rh.JSONGet("group", "_1")) if err != nil { log.Fatalf("Failed to JSONGet") return } var _1 interface{} err = json.Unmarshal(js1, &_1) if err != nil { return } fmt.Println("_1") fmt.Println(_1)
err = conn.Close() if err != nil { return }
cli := goredis.NewClient(&goredis.Options{Addr: "192.168.1.131:6379", Password: "", DB: 0, }) rh.SetGoRedisClient(cli) js2, err := redis.Bytes(rh.JSONGet("group", ".")) if err != nil { log.Fatalf("Failed to JSONGet") return } var group2 interface{} err = json.Unmarshal(js2, &group2) if err != nil { return } fmt.Println("group2") fmt.Println(group2) err = cli.Close() if err != nil { return } return }
|