summaryrefslogtreecommitdiff
path: root/redigo.go
blob: ff1bf3f17b652260c92158c3b11f8fb13aa81735 (plain)
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
package main

import (
    "github.com/go-redis/redis"
    "fmt"
)

func ExampleNewClient() {
    client := redis.NewClient(&redis.Options{
    Addr:     "192.168.0.16:6379",
    Password: "", // no password set
    DB:       0,  // use default DB
})

    pong, err := client.Ping().Result()
    fmt.Println(pong, err)
    // Output: PONG <nil>
}

func ExampleClient() {
    client := redis.NewClient(&redis.Options{
        Addr:     "192.168.0.16:6379",
        Password: "", // no password set
        DB:       0,  // use default DB
    })
    err := client.Set("key", "value", 0).Err()
    if err != nil {
        panic(err)
    }

    val, err := client.Get("key").Result()
    if err != nil {
        panic(err)
    }
    fmt.Println("key", val)

    val2, err := client.Get("key2").Result()
    if err == redis.Nil {
        fmt.Println("key2 does not exists")
    } else if err != nil {
        panic(err)
    } else {
    fmt.Println("key2", val2)
    }
// Output: key value
// key2 does not exists
}

func main() {
    ExampleNewClient()
}