From 69067c027812dada6a9476644534d1be9fee5383 Mon Sep 17 00:00:00 2001 From: Alexey Larkov Date: Mon, 29 Aug 2016 20:47:23 +0300 Subject: [PATCH] Add redis dbid config --- db.go | 7 +++++-- settings.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index 90d9c18..db1e65d 100644 --- a/db.go +++ b/db.go @@ -291,12 +291,12 @@ func (connector *DbConnector) GetChecksCount() (int64, error) { // InitRedisDatabase creates Redis pool based on config func InitRedisDatabase() { db = &DbConnector{ - Pool: NewRedisPool(fmt.Sprintf("%s:%s", config.Redis.Host, config.Redis.Port)), + Pool: NewRedisPool(fmt.Sprintf("%s:%s", config.Redis.Host, config.Redis.Port), config.Redis.DBID), } } // NewRedisPool creates Redis pool -func NewRedisPool(redisURI string) *redis.Pool { +func NewRedisPool(redisURI string, dbID ...int) *redis.Pool { return &redis.Pool{ MaxIdle: 3, IdleTimeout: 240 * time.Second, @@ -305,6 +305,9 @@ func NewRedisPool(redisURI string) *redis.Pool { if err != nil { return nil, err } + if len(dbID) > 0 { + c.Do("SELECT", dbID[0]) + } return c, err }, TestOnBorrow: func(c redis.Conn, t time.Time) error { diff --git a/settings.go b/settings.go index 09027a5..3e1835e 100644 --- a/settings.go +++ b/settings.go @@ -20,6 +20,7 @@ type NotifierConfig struct { type RedisConfig struct { Host string `yaml:"host"` Port string `yaml:"port"` + DBID int `yaml:"dbid"` } type FrontConfig struct {