中断训练
This commit is contained in:
parent
c3a6574372
commit
286d822a5b
@ -9,11 +9,11 @@
|
|||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
from app.utils.redis_config import redis_client
|
from app.utils.redis_config import redis_client
|
||||||
|
redis_client.init_redis_connect()
|
||||||
|
|
||||||
def _init(): # 初始化
|
def _init(): # 初始化
|
||||||
dict = {}
|
dict = {}
|
||||||
redis_client.__setattr__("_global_dict", json.dumps(dict))
|
redis_client.get_redis().set("_global_dict", json.dumps(dict))
|
||||||
|
|
||||||
|
|
||||||
def set_value(key, value):
|
def set_value(key, value):
|
||||||
@ -21,16 +21,16 @@ def set_value(key, value):
|
|||||||
dict = redis_client.get_redis().get("_global_dict")
|
dict = redis_client.get_redis().get("_global_dict")
|
||||||
if dict is None:
|
if dict is None:
|
||||||
dict = {}
|
dict = {}
|
||||||
|
else:
|
||||||
|
dict = json.loads(dict)
|
||||||
dict[key] = value
|
dict[key] = value
|
||||||
# redis_client.get_redis().set("_global_dict", json.dumps(dict))
|
redis_client.get_redis().set("_global_dict", json.dumps(dict))
|
||||||
redis_client.__setattr__("_global_dict", json.dumps(dict))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_value(key):
|
def get_value(key):
|
||||||
# 获得一个全局变量,不存在则提示读取对应变量失败
|
# 获得一个全局变量,不存在则提示读取对应变量失败
|
||||||
try:
|
try:
|
||||||
return redis_client.get_redis().get("_global_dict")[key]
|
dict = redis_client.get_redis().get("_global_dict")
|
||||||
except Exception as e:
|
return json.loads(dict)[key]
|
||||||
print(e)
|
except:
|
||||||
print('读取' + key + '失败\r\n')
|
print('读取' + key + '失败\r\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user