RODY/app/configs/global_var.py
2022-11-28 17:08:12 +08:00

34 lines
771 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
@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
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 = {}
dict[key] = value
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:
print('读取' + key + '失败\r\n')