提交 76fd7b38 编写于 作者: W wulorn

增加redis配置项,可通过配置文件配置指定的redis库

上级 3e8a6946
......@@ -6,6 +6,7 @@ query:
redis:
addrs:
- 127.0.0.1:6379
db: 0
pass: ""
# timeout:
# conn: 500
......
......@@ -52,6 +52,7 @@ link:
# for alarm event and message queue
redis:
addr: "127.0.0.1:6379"
db: 0
pass: ""
# in ms
# timeout:
......
......@@ -15,6 +15,7 @@ var Config RedisSection
type RedisSection struct {
Addrs []string `yaml:"addrs"`
Pass string `yaml:"pass"`
DB int `yaml:"db"`
Idle int `yaml:"idle"`
Timeout TimeoutSection `yaml:"timeout"`
Prefix string `yaml:"prefix"`
......@@ -31,6 +32,7 @@ func Init(cfg RedisSection) {
addrs := cfg.Addrs
pass := cfg.Pass
db := cfg.DB
maxIdle := cfg.Idle
idleTimeout := 240 * time.Second
......@@ -59,6 +61,15 @@ func Init(cfg RedisSection) {
}
}
if db != 0 {
if _, err := c.Do("SELECT", db); err != nil {
c.Close()
logger.Error("redis select db fail, db: ", db)
stats.Counter.Set("redis.conn.failed", 1)
return nil, err
}
}
return c, err
},
TestOnBorrow: PingRedis,
......
......@@ -43,6 +43,7 @@ type cleanerSection struct {
type redisSection struct {
Addr string `yaml:"addr"`
Pass string `yaml:"pass"`
DB int `yaml:"db"`
Idle int `yaml:"idle"`
Timeout timeoutSection `yaml:"timeout"`
}
......
......@@ -17,6 +17,7 @@ func InitRedis() {
addr := cfg.Redis.Addr
pass := cfg.Redis.Pass
db := cfg.Redis.DB
maxIdle := cfg.Redis.Idle
idleTimeout := 240 * time.Second
......@@ -44,6 +45,15 @@ func InitRedis() {
}
}
if db != 0 {
if _, err := c.Do("SELECT", db); err != nil {
c.Close()
logger.Error("redis select db fail, db: ", db)
stats.Counter.Set("redis.conn.failed", 1)
return nil, err
}
}
return c, err
},
TestOnBorrow: PingRedis,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册