From f0bd15f2eb0bf5539010c957c295af6ec1d50bf9 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 07 八月 2023 14:23:35 +0800 Subject: [PATCH] redis批量提交数据 --- code_attribute/big_money_num_manager.py | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/code_attribute/big_money_num_manager.py b/code_attribute/big_money_num_manager.py index 15a5baf..fb481a1 100644 --- a/code_attribute/big_money_num_manager.py +++ b/code_attribute/big_money_num_manager.py @@ -18,8 +18,14 @@ return False +__big_money_cache = {} + + def add_num(code, num): - RedisUtils.incrby(__redisManager.getRedis(), "big_money-{}".format(code), num) + if code not in __big_money_cache: + __big_money_cache[code] = 0 + __big_money_cache[code] += num + RedisUtils.incrby_async(__redisManager.getRedis(), "big_money-{}".format(code), num) # 璁剧疆杩囨湡鏃堕棿 @@ -28,6 +34,7 @@ def reset(code): + __big_money_cache[code] = 0 RedisUtils.set(__redisManager.getRedis(), "big_money-{}".format(code), 0) @@ -38,6 +45,14 @@ return round(int(num) / 1000 / 4) +def get_num_cache(code): + if code in __big_money_cache: + return __big_money_cache[code] + num = get_num(code) + __big_money_cache[code] = num + return num + + def reset_all(): redis = __redisManager.getRedis() try: -- Gitblit v1.8.0