diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2017-09-25 00:57:20 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2017-09-25 00:57:20 +0200 |
| commit | 931fdd01358989f6ab73e29c949449e9639d005b (patch) | |
| tree | 53fcb607abb9ead87a99b3d0bd7b0e2d557a8ff8 /redigo.go | |
| parent | 7e33d4d446d6b7d9a136290993363f833fc13908 (diff) | |
redigo - Simple redis client
Diffstat (limited to 'redigo.go')
| -rw-r--r-- | redigo.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/redigo.go b/redigo.go new file mode 100644 index 0000000..ff1bf3f --- /dev/null +++ b/redigo.go @@ -0,0 +1,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() +} |
