func InitRedisPools() { for name, conf := range setting.Cfg.Redis { log.Debug("InitRedisPools name %s, conf %v", name, conf) RedisPools[name] = newRedis(conf) } log.Debug("初始化redis连接池 done \n %v", RedisPools) }
func RedisCheckConn() { for name, pool := range RedisPools { go func(name string, pool *redis.Pool) { log.Debug("check Redis conn name : %s", name) conn := pool.Get() res, err := conn.Do("PING") if err != nil { log.Error(4, "redis name %s, conn failed %v", name, err) } else { log.Debug("redis name %s, conn ok %v", name, res) } conn.Close() }(name, pool) } }
func Slave() *xorm.Engine { name := setting.Cfg.DBSlave[slavePolling.Index()] x, ok := XormEngines[name] if !ok { panic(fmt.Errorf("Unknown Slave name %s", name)) } log.Debug("Slave use db name %s", name) return x }
func Master() *xorm.Engine { name := setting.Cfg.DBMaster[masterPolling.Index()] x, ok := XormEngines[name] if !ok { panic(fmt.Errorf("Unknown master name %s", name)) } log.Debug("Master use db name %s", name) return x }
func bootstraps() { setting.InitConfig() setting.InitServices() models.InitDatabaseConn() models.InitRedisPools() models.RedisCheckConn() log.Debug("%v", setting.Cfg) }
func InitDatabaseConn() { if len(setting.Cfg.DBMaster) == 0 || len(setting.Cfg.DBSlave) == 0 { panic("setting.Cfg.DBMaster & DBSlave must be set ") } for name, conf := range setting.Cfg.DBs { x, err := newEngine(conf) if err != nil { log.Error(4, "newEngine failed name %s %v", name, err) continue } XormEngines[name] = x } masterPolling = polling.NewPolling(len(setting.Cfg.DBMaster)) masterPolling = polling.NewPolling(len(setting.Cfg.DBSlave)) log.Debug("初始化 models done %v", XormEngines) }