dingxin_toolbox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.3 KiB

from django_redis import get_redis_connection
import json
import xmltodict
# 封装方法处理从redis中获取接口数据
def get_data_from_redis(redis_key):
# 初始化redis
redis_conn = get_redis_connection()
# 如果有用户数据则处理用户数据
if redis_conn.exists(redis_key + '_user_data'):
redis_data = json.loads(redis_conn.get(redis_key + '_user_data'))
user_data = redis_data['user_data']
print('user_data', json.dumps(user_data))
return True, redis_data['format'], user_data
# 没有用户数据时,随机选择数据
if redis_conn.exists(redis_key):
redis_data = json.loads(redis_conn.get(redis_key))
resp_data = []
resp = redis_data['handled_data']
print('handled_data', json.dumps(redis_data['handled_data']))
resp_result = resp['res']['status']
if str(resp_result) == '1':
resp_data = resp['res']['data']
if str(resp_result) != '1':
return False, redis_data['format'], '请检查接口返回值或手动输入参数:'
if len(resp_data) == 0:
return False, redis_data['format'], '接口返回数据为空,请手动输入参数:'
return True, redis_data['format'], resp_data
return False, 'json', '请手动输入参数,或先请求接口:'