def _init_from_conf(self): """根据配置初始化redis客户端连接 """ self.redis_pool = tree.create_tree() # 重置redis_pool # qconf的话特殊对待 if self.redis_local_flag is False: self.redis_conf = self._get_conf() LOG.info("init redis conf, redis_conf=%s", self.redis_conf) for url in self.redis_conf.itervalues(): options = parse_from_url(url) # 如果url不符合标准将会直接ValueError异常 client_name = options["client_name"] db = options["db"] weight = options["weight"] if int(weight) == 0: continue client = Client( host=options["host"], port=options["port"], db=db, transaction=options.get("transaction", False), ) if self.redis_pool[client_name][db]: self.redis_pool[client_name][db].extend([client] * weight) else: self.redis_pool[client_name][db] = [client] * weight
def _do_check_conf(self): """检测配置是否更新,如果配置有变更则重新加载配置信息 """ new_conf = self._get_conf() for k, v in new_conf.iteritems(): if self.redis_conf.get(k, None) != v: self._init_from_conf() LOG.info("run _do_check_conf, config has changed") break
def _init_from_conf(self): """根据配置初始化redis客户端连接 """ self.redis_pool = tree.create_tree() # 重置redis_pool self.redis_conf = self._get_conf() LOG.info("init redis conf, redis_conf=%s", self.redis_conf) for url in self.redis_conf.itervalues(): options = parse_from_url(url) # 如果url不符合标准将会直接ValueError异常 client_name = options["client_name"] db = options["db"] weight = options["weight"] if int(weight) == 0: continue client = Client( host=options["host"], port=options["port"], db=db, transaction=options.get("transaction", False), ) if self.redis_pool[client_name][db]: self.redis_pool[client_name][db].extend([client] * weight) else: self.redis_pool[client_name][db] = [client] * weight