Example #1
0
File: redis.go Project: hzmnet/api
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)

}
Example #2
0
File: redis.go Project: hzmnet/api
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)

	}
}
Example #3
0
File: models.go Project: hzmnet/api
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
}
Example #4
0
File: models.go Project: hzmnet/api
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
}
Example #5
0
File: main.go Project: hzmnet/api
func bootstraps() {
	setting.InitConfig()
	setting.InitServices()

	models.InitDatabaseConn()

	models.InitRedisPools()
	models.RedisCheckConn()

	log.Debug("%v", setting.Cfg)
}
Example #6
0
File: models.go Project: hzmnet/api
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)
}