From 500e2f3db6ce9ab2f6f06e7b3b23ce15f71db59d Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 03 八月 2023 11:19:21 +0800 Subject: [PATCH] redis封装 --- l2/code_price_manager.py | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/l2/code_price_manager.py b/l2/code_price_manager.py index a5b1071..98e1044 100644 --- a/l2/code_price_manager.py +++ b/l2/code_price_manager.py @@ -13,6 +13,7 @@ __redisManager = redis_manager.RedisManager(1) __latest_data = {} __current_buy_1_price = {} + __buy1_price_info_cache = {} @classmethod def __get_redis(cls): @@ -21,8 +22,9 @@ # 淇濆瓨涔�1浠锋牸淇℃伅 @classmethod def __save_buy1_price_info(cls, code, limit_up_time, open_limit_up_time): - RedisUtils.setex(cls.__get_redis(),f"buy1_price_limit_up_info-{code}", tool.get_expire(), - json.dumps((limit_up_time, open_limit_up_time))) + tool.CodeDataCacheUtil.set_cache(cls.__buy1_price_info_cache, code, (limit_up_time, open_limit_up_time)) + RedisUtils.setex(cls.__get_redis(), f"buy1_price_limit_up_info-{code}", tool.get_expire(), + json.dumps((limit_up_time, open_limit_up_time))) @classmethod def __get_buy1_price_info(cls, code): @@ -33,9 +35,18 @@ return data[0], data[1] @classmethod + def __get_buy1_price_info_cache(cls, code): + cache_result = tool.CodeDataCacheUtil.get_cache(cls.__buy1_price_info_cache, code) + if cache_result[0]: + return cache_result[1] + val = cls.__get_buy1_price_info(code) + tool.CodeDataCacheUtil.set_cache(cls.__buy1_price_info_cache, code, val) + return val + + @classmethod def __save_buy1_price(cls, code, buy_1_price): cls.__current_buy_1_price[code] = buy_1_price - RedisUtils.setex(cls.__get_redis(),f"buy1_price-{code}", tool.get_expire(), buy_1_price) + RedisUtils.setex(cls.__get_redis(), f"buy1_price-{code}", tool.get_expire(), buy_1_price) @classmethod def __get_buy1_price(cls, code): @@ -44,7 +55,7 @@ # 璁剧疆鐐告澘鍚庣殑鏈�浣庝环 @classmethod def __save_open_limit_up_lowest_price(cls, code, price): - RedisUtils.setex(cls.__get_redis(),f"open_limit_up_lowest_price-{code}", tool.get_expire(), f"{price}") + RedisUtils.setex(cls.__get_redis(), f"open_limit_up_lowest_price-{code}", tool.get_expire(), f"{price}") @classmethod def __get_open_limit_up_lowest_price(cls, code): @@ -85,7 +96,7 @@ return is_limit_up = abs(float(limit_up_price) - float(buy_1_price)) < 0.01 - old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) + old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) if old_limit_up_time and old_open_limit_up_time: return if is_limit_up and old_limit_up_time is None and float(sell_1_price) < 0.1 and int(sell_1_volumn) <= 0: @@ -102,7 +113,7 @@ # 鏄惁鍙互涓嬪崟 @classmethod def is_can_buy(cls, code): - old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) + old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) if old_limit_up_time and old_open_limit_up_time: return True return False @@ -111,7 +122,7 @@ # 杩斿洖娑ㄥ仠鏃堕棿涓庣偢鏉挎椂闂� @classmethod def get_limit_up_info(cls, code): - old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info(code) + old_limit_up_time, old_open_limit_up_time = cls.__get_buy1_price_info_cache(code) return old_limit_up_time, old_open_limit_up_time # 璁剧疆娑ㄥ仠鏃堕棿 -- Gitblit v1.8.0