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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-09-29
  • 2022-03-04
  • 2021-06-10
  • 2021-11-10
  • 2021-08-20
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-02-04
  • 2021-11-25
  • 2021-08-06
  • 2021-09-30
  • 2021-09-13
相关资源
相似解决方案