From b4480ad745510c8e81c88c20fb67cb65eef79cc5 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 17 八月 2023 11:05:23 +0800 Subject: [PATCH] ++++++++++++++++ bug修复 --- third_data/code_plate_key_manager.py | 34 ++++++++++++++++++++++++++++------ 1 files changed, 28 insertions(+), 6 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index 407ab9c..8e36034 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -6,11 +6,11 @@ import json import constant -from db.redis_manager import RedisUtils +from db.redis_manager_delegate import RedisUtils from third_data import kpl_block_util from utils import global_util, tool from log_module import log -from db import redis_manager +from db import redis_manager_delegate as redis_manager from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy, logger_kpl_debug from third_data.kpl_util import KPLPlatManager @@ -48,16 +48,38 @@ # 寮�鐩樺暒绂佹浜ゆ槗鏉垮潡绠$悊 class KPLPlateForbiddenManager: __redisManager = redis_manager.RedisManager(3) + __kpl_forbidden_plates_cache = set() - def __get_redis(self): - return self.__redisManager.getRedis() + __instance = None + + def __new__(cls, *args, **kwargs): + if not cls.__instance: + cls.__instance = super(KPLPlateForbiddenManager, cls).__new__(cls, *args, **kwargs) + cls.__load_datas() + return cls.__instance + + @classmethod + def __load_datas(cls): + __redis = cls.__get_redis() + try: + __kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "kpl_forbidden_plates") + finally: + RedisUtils.realse(__redis) + + @classmethod + def __get_redis(cls): + return cls.__redisManager.getRedis() def save_plate(self, plate): + self.__kpl_forbidden_plates_cache.add(plate) RedisUtils.sadd(self.__get_redis(), "kpl_forbidden_plates", plate) RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire()) def list_all(self): return RedisUtils.smembers(self.__get_redis(), "kpl_forbidden_plates") + + def list_all_cache(self): + return self.__kpl_forbidden_plates_cache class LimitUpCodesPlateKeyManager: @@ -217,7 +239,7 @@ # 鍚庢帓鎵嶈兘鎸傚崟 return 0, "韬綅涓嶄负鍚庢帓" - forbidden_plates = cls.__KPLPlateForbiddenManager.list_all() + forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache() if key in forbidden_plates: return 0, "涓嶄拱璇ユ澘鍧�" @@ -236,7 +258,7 @@ def is_in_top(cls, keys): reasons = cls.get_can_buy_key_set() log.logger_kpl_debug.debug("甯傚満娴佸叆鍓�5:{}", reasons) - forbidden_plates = cls.__KPLPlateForbiddenManager.list_all() + forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache() reasons = reasons - forbidden_plates temp_set = keys & reasons log.logger_kpl_debug.debug("甯傚満娴佸叆鍓�5鍖归厤缁撴灉:{}", temp_set) -- Gitblit v1.8.0