From ba52d7ac92a36f413eacaa686f8535e859664ec6 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 28 八月 2023 09:45:11 +0800 Subject: [PATCH] bug修改 --- l2/l2_data_util.py | 29 +++++++++++++---------------- 1 files changed, 13 insertions(+), 16 deletions(-) diff --git a/l2/l2_data_util.py b/l2/l2_data_util.py index 6a412dc..633de90 100644 --- a/l2/l2_data_util.py +++ b/l2/l2_data_util.py @@ -13,10 +13,10 @@ import constant from code_attribute import gpcode_manager -from db.redis_manager import RedisUtils +from db.redis_manager_delegate import RedisUtils from l2 import l2_data_log, l2_data_source_util from log_module import log, log_export -from db import redis_manager +from db import redis_manager_delegate as redis_manager from utils import tool _redisManager = redis_manager.RedisManager(1) @@ -34,12 +34,11 @@ def load_l2_data(code, load_latest=True, force=False): - redis = _redisManager.getRedis() # 鍔犺浇鏈�杩戠殑l2鏁版嵁 if load_latest: if local_latest_datas.get(code) is None or force: # 鑾峰彇鏈�杩戠殑鏁版嵁 - _data = RedisUtils.get(redis, "l2-data-latest-{}".format(code)) + _data = RedisUtils.get(_redisManager.getRedis(), "l2-data-latest-{}".format(code)) if _data is not None: if code in local_latest_datas: local_latest_datas[code] = json.loads(_data) @@ -118,28 +117,29 @@ redis_instance = _redisManager.getRedis() try: - if RedisUtils.setnx(redis_instance, "l2-save-{}".format(code), "1") > 0: + if RedisUtils.setnx(redis_instance, "l2-save-{}".format(code), "1", auto_free=False) > 0: # 璁$畻淇濈暀鐨勬椂闂� expire = tool.get_expire() i = 0 for _data in datas: i += 1 key = "l2-" + _data["key"] - value = RedisUtils.get(redis_instance, key) + value = RedisUtils.get(redis_instance, key, auto_free=False) if value is None: # 鏂板 try: value = {"index": _data["index"], "re": _data["re"]} - RedisUtils.setex(redis_instance, key, expire, json.dumps(value)) + RedisUtils.setex(redis_instance, key, expire, json.dumps(value), auto_free=False) except: logging.error("鏇存L2鏁版嵁鍑洪敊锛歿} key:{}".format(code, key)) else: json_value = json.loads(value) if json_value["re"] != _data["re"]: json_value["re"] = _data["re"] - RedisUtils.setex(redis_instance, key, expire, json.dumps(json_value)) + RedisUtils.setex(redis_instance, key, expire, json.dumps(json_value), auto_free=False) finally: - RedisUtils.delete(redis_instance, "l2-save-{}".format(code)) + RedisUtils.delete(redis_instance, "l2-save-{}".format(code), auto_free=False) + RedisUtils.realse(redis_instance) print("淇濆瓨鏂版暟鎹敤鏃讹細", msg, "鑰楁椂锛歿}".format(round(time.time() * 1000) - start_time)) return datas @@ -147,14 +147,13 @@ # 淇濆瓨l2鏁版嵁 def save_l2_data(code, datas, add_datas): - redis = _redisManager.getRedis() # 鍙湁鏈夋柊鏇炬暟鎹墠闇�瑕佷繚瀛� if len(add_datas) > 0: # 淇濆瓨鏈�杩戠殑鏁版嵁 __start_time = round(time.time() * 1000) if datas: - RedisUtils.setex(redis, "l2-data-latest-{}".format(code), tool.get_expire(), json.dumps(datas)) - l2_data_log.l2_time(code, round(time.time() * 1000) - __start_time, "淇濆瓨鏈�杩憀2鏁版嵁鐢ㄦ椂") + RedisUtils.setex_async(_redisManager.getRedis(), "l2-data-latest-{}".format(code), tool.get_expire(), json.dumps(datas)) + # l2_data_log.l2_time(code, round(time.time() * 1000) - __start_time, "淇濆瓨鏈�杩憀2鏁版嵁鐢ㄦ椂") # 璁剧疆杩涘唴瀛� local_latest_datas[code] = datas set_l2_data_latest_count(code, len(datas)) @@ -168,9 +167,8 @@ # 璁剧疆鏈�鏂扮殑l2鏁版嵁閲囬泦鐨勬暟閲� def set_l2_data_latest_count(code, count): - redis = _redisManager.getRedis() key = "latest-l2-count-{}".format(code) - RedisUtils.setex(redis, key, 2, count) + RedisUtils.setex(_redisManager.getRedis(), key, 2, count) pass @@ -178,10 +176,9 @@ def get_l2_data_latest_count(code): if code is None or len(code) < 1: return 0 - redis = _redisManager.getRedis() key = "latest-l2-count-{}".format(code) - result = RedisUtils.get(redis, key) + result = RedisUtils.get(_redisManager.getRedis(), key) if result is None: return 0 else: -- Gitblit v1.8.0