Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Add redis dbid config
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlexx committed Aug 29, 2016
1 parent 460123f commit 69067c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 69067c0

Please sign in to comment.