From 286d822a5b44522b15a86a59ffec219798cedd1f Mon Sep 17 00:00:00 2001 From: JIAKUNHAO Date: Tue, 29 Nov 2022 16:12:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E6=96=AD=E8=AE=AD=E7=BB=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/configs/global_var.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/configs/global_var.py b/app/configs/global_var.py index e64350a..727e51d 100644 --- a/app/configs/global_var.py +++ b/app/configs/global_var.py @@ -9,11 +9,11 @@ """ import json from app.utils.redis_config import redis_client - +redis_client.init_redis_connect() def _init(): # 初始化 dict = {} - redis_client.__setattr__("_global_dict", json.dumps(dict)) + redis_client.get_redis().set("_global_dict", json.dumps(dict)) def set_value(key, value): @@ -21,16 +21,16 @@ def set_value(key, value): dict = redis_client.get_redis().get("_global_dict") if dict is None: dict = {} + else: + dict = json.loads(dict) dict[key] = value - # redis_client.get_redis().set("_global_dict", json.dumps(dict)) - redis_client.__setattr__("_global_dict", json.dumps(dict)) - + redis_client.get_redis().set("_global_dict", json.dumps(dict)) def get_value(key): # 获得一个全局变量,不存在则提示读取对应变量失败 try: - return redis_client.get_redis().get("_global_dict")[key] - except Exception as e: - print(e) + dict = redis_client.get_redis().get("_global_dict") + return json.loads(dict)[key] + except: print('读取' + key + '失败\r\n')