gin+redis

var RedisDefaultPool *redis.Pool

func newPool(addr string) *redis.Pool {
    return &redis.Pool{
        MaxIdle:     3,
        MaxActive:   0,
        IdleTimeout: 240 * time.Second,
        Dial: func() (conn redis.Conn, e error) {
            return redis.Dial("tcp", addr)
        },
    }
}

func init() {
    RedisDefaultPool = newPool("127.0.0.1:6379")
}

// 使用下面的方法从连接池返回一个连接
conn := RedisDefaultPool.Get()
ret, err := redis.String(conn.Do("get", "name"))




posted @ 2019-12-20 00:33  离地最远的星  阅读(2772)  评论(0编辑  收藏  举报