From 500e2f3db6ce9ab2f6f06e7b3b23ce15f71db59d Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 03 八月 2023 11:19:21 +0800 Subject: [PATCH] redis封装 --- code_attribute/gpcode_first_screen_manager.py | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/code_attribute/gpcode_first_screen_manager.py b/code_attribute/gpcode_first_screen_manager.py index 5bc3366..2f88333 100644 --- a/code_attribute/gpcode_first_screen_manager.py +++ b/code_attribute/gpcode_first_screen_manager.py @@ -17,6 +17,9 @@ return __redisManager.getRedis() +__first_code_data_cache = {} + + # 淇濆瓨棣栨澘绁ㄧ殑鏁版嵁 # 1.棣栨娑ㄥ仠鏃堕棿 # 2.鏈�杩戞定鍋滄椂闂� @@ -24,6 +27,7 @@ # 4.鏈�杩戠偢寮�鏃堕棿 # 5.鏄惁宸茬粡娑ㄥ仠 def __save_first_code_data(code, data): + tool.CodeDataCacheUtil.set_cache(__first_code_data_cache, code, data) RedisUtils.setex(__redisManager.getRedis(), f"first_code_data-{code}", tool.get_expire(), json.dumps(data)) @@ -32,6 +36,15 @@ if val is None: return None return json.loads(val) + + +def __get_first_code_data_cache(code): + cache_result = tool.CodeDataCacheUtil.get_cache(__first_code_data_cache, code) + if cache_result[0]: + return cache_result[1] + val = __get_first_code_data(code) + tool.CodeDataCacheUtil.set_cache(__first_code_data_cache, code, val) + return val # 娣诲姞杩涢鏉挎湭绛涢�夌エ @@ -67,7 +80,7 @@ for price in prices: code = price["code"] time_ = price["time"] - old_data = __get_first_code_data(code) + old_data = __get_first_code_data_cache(code) if old_data is None: continue limit_up = price["limit_up"] -- Gitblit v1.8.0