123456789101112131415161718192021222324252627282930313233343536373839 |
- package ads_redis
- import (
- "fmt"
- "miads/adslib"
- "time"
- "github.com/gomodule/redigo/redis"
- )
- var RedisConn *redis.Pool
- func Setup() error {
- host := adslib.GetConf().RedisHost
- password := adslib.GetConf().RedisPassword
- RedisConn = &redis.Pool{
- MaxIdle: 20,
- MaxActive: 50,
- IdleTimeout: 3 * time.Minute,
- Dial: func() (redis.Conn, error) {
- c, err := redis.Dial("tcp", host)
- if err != nil {
- fmt.Println(err)
- return nil, err
- }
- if password != "" {
- if _, err := c.Do("AUTH", password); err != nil {
- fmt.Println(err)
- c.Close()
- return nil, err
- }
- }
- return c, err
- },
- }
- return nil
- }
|