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"))





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM