1. redigo
2. 示例
// redis_demo project main.go
package main
import (
"fmt"
"github.com/redigo/redis"
)
func main() {
c, err := redis.Dial("tcp", "10.1.64.80:6379")
if err != nil {
fmt.Println("Connect to redis error", err)
return
}
defer c.Close()
_, err = c.Do("SET", "mykey", "superWang")
if err != nil {
fmt.Println("redis set failed:", err)
}
username, err := redis.String(c.Do("GET", "mykey"))
if err != nil {
fmt.Println("redis get failed:", err)
} else {
fmt.Printf("Get mykey: %v \n", username)
}
result, err := redis.Strings(c.Do("SMEMBERS", "set_numbers"))
if err != nil {
fmt.Println("redis get failed:", err)
} else {
fmt.Printf("Get mykey: %v \n", result)
}
}