# -*- coding: utf-8 -*- """ @Time : 2023/3/2 19:31 @Author : @FileName: @Software: @Describe: """ # # import redis # # redis_pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password='', db=0) # redis_conn = redis.Redis(connection_pool=redis_pool) # # # name_dict = { # 'name_4' : 'Zarten_4', # 'name_5' : 'Zarten_5' # } # redis_conn.mset(name_dict) import flask import redis import uuid import json from threading import Thread import time app = flask.Flask(__name__) pool = redis.ConnectionPool(host='localhost', port=63179, max_connections=100, db=13, password="zhicheng123*") redis_ = redis.Redis(connection_pool=pool, decode_responses=True) @app.route("/search", methods=["POST"]) def handle_query(): # try: id_ = flask.request.json['orderid'] # 获取用户query中的文本 result = redis_.get(id_) # 获取该query的模型结果 if result is not None: # redis_.delete(id_) result_path = result.decode('UTF-8') with open(result_path, encoding='utf8') as f1: # 加载文件的对象 result_dict = json.load(f1) resilt = result_dict["resilt"] result_text = {'status': 9, 'resilt': resilt, 'reportId': "", 'downloadurl': "", 'similarity': "" } else: result_text = {'status': 1, 'resilt': "", 'reportId': "", 'downloadurl': "", 'similarity': "" } result = {'code':0, "msg": "请求成功", "data": result_text} # except: # result = {'code':1, # "msg": "请求失败" # } return flask.jsonify(result) # 返回结果 if __name__ == "__main__": app.run(debug=False, host='0.0.0.0', port=16006)