liuxiaolong
2020-06-29 167f00c02df35f19d689e60db3d30ebf035ab629
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package cache
 
import (
    "fmt"
    "github.com/astaxie/beego"
    redigo "github.com/gomodule/redigo/redis"
)
 
var pool *redigo.Pool
 
func init() {
    redisHost := beego.AppConfig.String("redisIp")
    redisPort := beego.AppConfig.String("redisPort")
    poolSize := 20
    pool = redigo.NewPool(func() (redigo.Conn, error) {
        c, err := redigo.Dial("tcp", fmt.Sprintf("%s:%d", redisHost, redisPort))
        if err != nil {
            return nil, err
        }
        return c, nil
    }, poolSize)
}
 
func Get() redigo.Conn {
    return pool.Get()
}