|
@@ -16,12 +16,16 @@ var RedisPool map[string]*redigo.Pool
|
|
|
|
|
|
//初始化redis 1为多个连接池,2为共用一个连接池
|
|
|
func InitRedis(addrs string) {
|
|
|
+ InitRedisBySize(addrs, 1000, 500, 240)
|
|
|
+}
|
|
|
+
|
|
|
+func InitRedisBySize(addrs string, maxSize, maxIdle, timeout int) {
|
|
|
RedisPool = map[string]*redigo.Pool{}
|
|
|
addr := strings.Split(addrs, ",")
|
|
|
for _, v := range addr {
|
|
|
saddr := strings.Split(v, "=")
|
|
|
- RedisPool[saddr[0]] = &redigo.Pool{MaxActive: 1000, MaxIdle: 800,
|
|
|
- IdleTimeout: 240 * time.Second, Dial: func() (redigo.Conn, error) {
|
|
|
+ RedisPool[saddr[0]] = &redigo.Pool{MaxActive: maxSize, MaxIdle: maxIdle,
|
|
|
+ IdleTimeout: time.Duration(timeout) * time.Second, Dial: func() (redigo.Conn, error) {
|
|
|
c, err := redigo.Dial("tcp", saddr[1])
|
|
|
if err != nil {
|
|
|
return nil, err
|