嫌连接池没被占用?
这样写
package main
import "github.com/garyburd/redigo/redis"
import (
"flag"
"fmt"
"time"
)
func newPool(addr string) *redis.Pool {
return &redis.Pool{
MaxIdle: 30,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) { return redis.Dial("tcp", addr) },
}
}
var (
pool *redis.Pool
redisServer = flag.String("redisServer", ":6379", "")
)
func main() {
flag.Parse()
pool = newPool(*redisServer)
fmt.Println(pool)
conn := pool.Get()
conn2 := pool.Get()
conn3 := pool.Get()
conn4 := pool.Get()
conn.Do("get", "a")
conn2.Do("get", "a")
conn3.Do("get", "a")
conn4.Do("get", "a")
//这里使劲加connX,就能看到效果了
//defer conn.Close()
//defer conn2.Close()
//defer conn3.Close()
//defer conn4.Close()
time.Sleep(100 * time.Second)
}