#!/usr/bin/env python # -*- coding:utf-8 -*- import json import logging import redis class Config: local_config = None redis_config = None def __init__(self, path): self.path = path def read_local_config(self): try: f = open(self.path) self.local_config = json.load(f) except Exception as e: logging.error("[CONFIG] read config with path: %s error: %s", self.path, e) def read_redis_config(self): if self.local_config is None: return None host = self.local_config["redis_host"] port = self.local_config["redis_port"] db = self.local_config['redis_db'] password = self.local_config['redis_password'] try: r = redis.Redis(host, port, db=db, password=password) config = r.get('config').decode('utf8') if config is None or config is "": return self.redis_config = json.loads(config) except Exception as e: print(e)