HIDE_END
()
| 11 | |
| 12 | // HIDE_END |
| 13 | func ExampleClient_setget() { |
| 14 | ctx := context.Background() |
| 15 | |
| 16 | rdb := redis.NewClient(&redis.Options{ |
| 17 | Addr: "localhost:6379", |
| 18 | Password: "", // no password docs |
| 19 | DB: 0, // use default DB |
| 20 | }) |
| 21 | |
| 22 | // REMOVE_START |
| 23 | // make sure we are working with fresh database |
| 24 | rdb.FlushDB(ctx) |
| 25 | rdb.Del(ctx, "bike") |
| 26 | // REMOVE_END |
| 27 | |
| 28 | // STEP_START set_get |
| 29 | res1, err := rdb.JSONSet(ctx, "bike", "$", |
| 30 | "\"Hyperion\"", |
| 31 | ).Result() |
| 32 | |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
| 36 | |
| 37 | fmt.Println(res1) // >>> OK |
| 38 | |
| 39 | res2, err := rdb.JSONGet(ctx, "bike", "$").Result() |
| 40 | |
| 41 | if err != nil { |
| 42 | panic(err) |
| 43 | } |
| 44 | |
| 45 | fmt.Println(res2) // >>> ["Hyperion"] |
| 46 | |
| 47 | res3, err := rdb.JSONType(ctx, "bike", "$").Result() |
| 48 | |
| 49 | if err != nil { |
| 50 | panic(err) |
| 51 | } |
| 52 | |
| 53 | fmt.Println(res3) // >>> [[string]] |
| 54 | // STEP_END |
| 55 | |
| 56 | // Output: |
| 57 | // OK |
| 58 | // ["Hyperion"] |
| 59 | // [[string]] |
| 60 | } |
| 61 | |
| 62 | func ExampleClient_str() { |
| 63 | ctx := context.Background() |