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.
111 lines
3.2 KiB
111 lines
3.2 KiB
2 years ago
|
# -*- coding:utf-8 -*-
|
||
|
# @Time: 2023/8/28 15:03
|
||
|
# @Author:ZYP
|
||
|
# @File:demo01_test_redis.py
|
||
|
# @mail:zypsunshine1@gmail.com
|
||
|
# # @Software: PyCharm
|
||
|
import time
|
||
|
|
||
|
import flask
|
||
|
import redis
|
||
|
import uuid
|
||
|
import json
|
||
|
import requests
|
||
|
# from util import Logging
|
||
|
# from threading import Thread
|
||
|
# from mysql_collect import mysql
|
||
|
# from SearchSimPaper import search_sim_paper
|
||
|
# import jieba
|
||
|
from flask import request
|
||
|
|
||
|
# import multiprocessing
|
||
|
|
||
|
app_check = flask.Flask(__name__)
|
||
|
pool = redis.ConnectionPool(host='192.168.31.145', port=63179, max_connections=50, password='zhicheng123*', db=8)
|
||
|
redis_ = redis.Redis(connection_pool=pool, decode_responses=True)
|
||
|
|
||
|
# pool1 = redis.ConnectionPool(host='192.168.31.145', port=63179, max_connections=50, password='zhicheng123*', db=11)
|
||
|
# redis_1 = redis.Redis(connection_pool=pool1, decode_responses=True)
|
||
|
|
||
|
# jieba.initialize()
|
||
|
|
||
|
db_key_query = 'query'
|
||
|
|
||
|
|
||
|
# db_key_result = 'result'
|
||
|
|
||
|
# log = Logging()
|
||
|
|
||
|
|
||
|
# def check_main_func():
|
||
|
# while True:
|
||
|
# if redis_.llen(db_key_query) == 0:
|
||
|
# continue
|
||
|
# while True:
|
||
|
# ss = redis_.rpop(db_key_query)
|
||
|
# if ss is None:
|
||
|
# time.sleep(2)
|
||
|
# else:
|
||
|
# break
|
||
|
#
|
||
|
# paper_data = json.loads(ss.decode())
|
||
|
# id_ = paper_data["id"]
|
||
|
# message_dict = paper_data["paper"]
|
||
|
# class_res = \
|
||
|
# json.loads(requests.post('http://192.168.31.145:50003/roformer', data=json.dumps(message_dict)).text)[
|
||
|
# 'label_num']
|
||
|
#
|
||
|
# sim_paper_id_dict = search_sim_paper(message_dict, class_res, mysql, log)
|
||
|
# redis_.set(id_, json.dumps(sim_paper_id_dict))
|
||
|
|
||
|
|
||
|
@app_check.route("/check", methods=["POST"])
|
||
|
def handle_query():
|
||
|
s = time.time()
|
||
|
message_dict = json.loads(request.data.decode())
|
||
|
uuid_request = str(message_dict['uuid'])
|
||
|
id_ = str(uuid.uuid1()) # 为query生成唯一标识
|
||
|
d = {'id': id_, 'paper': message_dict} # 绑定文本和query id
|
||
|
redis_.rpush(db_key_query, json.dumps(d))
|
||
|
while True:
|
||
|
result = redis_.get(id_)
|
||
|
if result is not None:
|
||
|
redis_.delete(id_)
|
||
|
result_text = {'uuid': uuid_request, 'data': result.decode('UTF-8')}
|
||
|
# result_text = json.loads(result.decode('UTF-8'))
|
||
|
break
|
||
|
e = time.time()
|
||
|
print('{} 花费了{} s 的时间'.format(uuid_request, (e - s)))
|
||
|
|
||
|
redis_.lpush('query_recall', json.dumps(result_text))
|
||
|
|
||
|
return uuid_request # 返回结果
|
||
|
|
||
|
|
||
|
# # return '1'
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
# for i in range(2):
|
||
|
# t = Thread(target=check_main_func, args=())
|
||
|
# t.start()
|
||
|
# processes = []
|
||
|
#
|
||
|
# # 创建并启动多个进程
|
||
|
# for i in range(2):
|
||
|
# process = multiprocessing.Process(target=check_main_func, args=())
|
||
|
# processes.append(process)
|
||
|
# process.start()
|
||
|
|
||
|
app_check.run(debug=False, host='0.0.0.0', port=50004)
|
||
|
|
||
|
# res = redis_.rpop(db_key_query)
|
||
|
# print(res)
|
||
|
|
||
|
# id_ = "51bc72dc-464e-11ee-baf3-45147420c4fb"
|
||
|
# res = redis_.get(id_)
|
||
|
# if res is not None:
|
||
|
# redis_.delete(id_)
|
||
|
# result_text = {'code': "200", 'data': res.decode('UTF-8')}
|
||
|
# print(result_text)
|