def __init__(self): try: confObj = ReadConfig() host = confObj.get_config("redis", "REDIS_HOST") port = confObj.get_config("redis", "REDIS_PORT") bucket = confObj.get_config("redis", "REDIS_BUCKET") if confObj.get_config( "redis", "REDIS_BUCKET") else 0 pwd = confObj.get_config("redis", "REDIS_PWD") if confObj.get_config( "redis", "REDIS_PWD") else None self.ex = confObj.get_config("redis", "REDIS_EXPIRETIME") self.conn = redis.Redis(host=host, port=port, password=pwd, db=bucket) self._label = os.path.abspath(os.path.dirname(os.getcwd())).split( os.path.sep) self._label.reverse() except Exception as e: logging.error("Redis connection failed, error message:%s", e)
def __init__(self, name): self.redisObj = redisbase.RedisBase() runenv = self.redisObj.get("runenv_py") if runenv == False: runenv = "trunk" confObj = ReadConfig() runenv = "trunk" if name == "fle": host = confObj.get_config(runenv, "database_fle_host") user = confObj.get_config(runenv, "database_fle_username") password = confObj.get_config(runenv, "database_fle_password") database = confObj.get_config(runenv, "database_fle_dbname") port = confObj.get_config(runenv, "database_fle_port") elif name == "bi": host = confObj.get_config(runenv, "database_rbi_host") user = confObj.get_config(runenv, "database_rbi_username") password = confObj.get_config(runenv, "database_rbi_password") database = confObj.get_config(runenv, "database_rbi_dbname") port = confObj.get_config(runenv, "database_rbi_port") else: host = confObj.get_config(runenv, "database_rbi_host") user = confObj.get_config(runenv, "database_rbi_username") password = confObj.get_config(runenv, "database_rbi_password") database = confObj.get_config(runenv, "database_rbi_dbname") port = confObj.get_config(runenv, "database_rbi_port") self._db_args = dict(use_unicode=True, charset="utf8", host=host, user=user, password=password, database=database, port=int(port), db=database, init_command='SET time_zone = "+8:00"', sql_mode="TRADITIONAL") self._db = None try: self.reconnect() except pymysql.Error: logging.error("Cannot connect to MySQL on %s", host, exc_info=True)