From 8595dc22aa9dde6aba6d0f8cdcf1656a8a59513b Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 02 八月 2023 18:05:10 +0800 Subject: [PATCH] redis封装 --- code_attribute/code_volumn_manager.py | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/code_attribute/code_volumn_manager.py b/code_attribute/code_volumn_manager.py index 247ac10..23bb5f8 100644 --- a/code_attribute/code_volumn_manager.py +++ b/code_attribute/code_volumn_manager.py @@ -7,6 +7,7 @@ # yesterday 鏄ㄥぉ鐨勯噺 import json +from db.redis_manager import RedisUtils from utils import global_util, tool from db import redis_manager from log_module.log import logger_day_volumn @@ -19,8 +20,8 @@ redis = __redis_manager.getRedis() global_util.max60_volumn[code] = (max60, max60_day) global_util.yesterday_volumn[code] = yesterday - redis.setex("volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day))) - redis.setex("volumn_yes-{}".format(code), tool.get_expire(), yesterday) + RedisUtils.setex(redis, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day))) + RedisUtils.setex(redis, "volumn_yes-{}".format(code), tool.get_expire(), yesterday) # 鑾峰彇鍘嗗彶閲� @@ -29,11 +30,11 @@ yesterday = global_util.yesterday_volumn.get(code) redis = __redis_manager.getRedis() if max60 is None: - max60 = redis.get("volumn_max60-{}".format(code)) + max60 = RedisUtils.get(redis, "volumn_max60-{}".format(code)) if max60: max60 = json.loads(max60) if yesterday is None: - yesterday = redis.get("volumn_yes-{}".format(code)) + yesterday = RedisUtils.get(redis, "volumn_yes-{}".format(code)) return max60, yesterday @@ -42,15 +43,15 @@ logger_day_volumn.info("code:{} volumn:{}".format(code, volumn)) redis = __redis_manager.getRedis() global_util.today_volumn[code] = volumn - redis.setex("volumn_today-{}".format(code), tool.get_expire(), volumn) + RedisUtils.setex(redis, "volumn_today-{}".format(code), tool.get_expire(), volumn) # 鑾峰彇浠婃棩閲� def get_today_volumn(code): _volumn = global_util.today_volumn.get(code) - redis = __redis_manager.getRedis() if _volumn is None: - _volumn = redis.get("volumn_today-{}".format(code)) + redis = __redis_manager.getRedis() + _volumn = RedisUtils.get(redis, "volumn_today-{}".format(code)) return _volumn @@ -91,20 +92,20 @@ # 灏嗛噺浠庢暟鎹簱鍔犲叆鍐呭瓨 def load(): redis = __redis_manager.getRedis() - keys = redis.keys("volumn_max60-*") + keys = RedisUtils.keys(redis, "volumn_max60-*") if keys is not None: for k in keys: code = k.split("-")[1] - max60_volumn = redis.get(k) + max60_volumn = RedisUtils.get(redis, k) if max60_volumn: max60_volumn = json.loads(max60_volumn) global_util.max60_volumn[code] = max60_volumn - keys = redis.keys("volumn_yes-*") + keys = RedisUtils.keys(redis, "volumn_yes-*") if keys is not None: for k in keys: code = k.split("-")[1] - global_util.yesterday_volumn[code] = redis.get(k) + global_util.yesterday_volumn[code] = RedisUtils.get(redis, k) if __name__ == "__main__": - print(get_volume_rate("000059")) \ No newline at end of file + print(get_volume_rate("000059")) -- Gitblit v1.8.0