中断训练

This commit is contained in:
wudong 2022-11-29 16:17:20 +08:00
commit fcc1439e2d

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
""" """
@Time 2022/11/15 10:13 @Time 2022/11/15 10:13
@Auth @Auth
@ -42,3 +43,41 @@ def get_value(key):
return _global_dict[key] return _global_dict[key]
except: except:
print('读取' + key + '失败\r\n') print('读取' + key + '失败\r\n')
=======
"""
@Time 2022/11/15 10:13
@Auth
@File global_var.py
@IDE PyCharm
@MottoABC(Always Be Coding)
@Desc
"""
import json
from app.utils.redis_config import redis_client
redis_client.init_redis_connect()
def _init(): # 初始化
dict = {}
redis_client.get_redis().set("_global_dict", json.dumps(dict))
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))
def get_value(key):
# 获得一个全局变量,不存在则提示读取对应变量失败
try:
dict = redis_client.get_redis().get("_global_dict")
return json.loads(dict)[key]
except:
print('读取' + key + '失败\r\n')
>>>>>>> 286d822a5b44522b15a86a59ffec219798cedd1f