在gopath 目录下安装 go get github.com/garyburd/redigo/redis

package main
import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

//定义一个全局链接池变量
var pool *redis.Pool

//在main函数之前执行
func init() {	
	pool = &redis.Pool{
		MaxIdle: 8, //最大空闲链接数
		MaxActive: 0, //最大链接数,0不限
		IdleTimeout: 100, //最大空闲是时间
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", "192.168.166.35:6379", redis.DialPassword("Wintel51971355"), redis.DialDatabase(14))
		},
	}
}

func main () {	
	conn,err := redis.Dial("tcp", "192.168.166.35:6379", redis.DialPassword("Wintel51971355"), redis.DialDatabase(14))
	defer conn.Close()
	if err != nil {
		fmt.Println("connect redis err", err)
		return 
	}
	//fmt.Println("conn success", conn)

	_, err = conn.Do("Set", "name", "test哈罗")
	if err != nil {
		fmt.Println("set error", err)
		return 
	}
	name, err := redis.String(conn.Do("Get", "name"))
	if err != nil {
		fmt.Println("get error", err)
		return 
	}

	fmt.Println("get res", name)

	conn.Do("HMSET", "testKey", "field1", "val1", "field2", "val2")
	conn.Do("expire", "testKey", 3600)
	res,err := redis.Strings(conn.Do("HMGET", "testKey", "field1", "field2"))
	fmt.Println("res",res)
	for i,v := range res {
		fmt.Printf("i=%d,v=%v \n", i, v)
	}

	//从连接池中取链接
	conn2 := pool.Get()
	conn2.Do("set", "test2", "123")
	fmt.Println(redis.String(conn2.Do("get", "test2")))
}
```
12-18 23:43