$ wget http://download.redis.io/releases/redis-3.0.3.tar.gz
$ tar xzf redis-3.0.3.tar.gz
$ cd redis-3.0.3
$ make
src/redis-server
-------------------------------------
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
--------------------------------------
go get gopkg.in/redis.v3
---------
package main
import (
"gopkg.in/redis.v3"
"fmt"
)
func main() {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
defer client.Close()
pong, err := client.Ping().Result()
fmt.Println(pong, err)
// Output: PONG <nil>
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)
}
有疑问加站长微信联系(非本文作者)