Exemple #1
0
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)

}
Exemple #2
0
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)

	}
}
Exemple #3
0
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
}
Exemple #4
0
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
}
Exemple #5
0
func bootstraps() {
	setting.InitConfig()
	setting.InitServices()

	models.InitDatabaseConn()

	models.InitRedisPools()
	models.RedisCheckConn()

	log.Debug("%v", setting.Cfg)
}
Exemple #6
0
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)
}