AI事件重复推送
This commit is contained in:
33
hik_push/subscribe.py
Normal file
33
hik_push/subscribe.py
Normal file
@ -0,0 +1,33 @@
|
||||
import json
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, BackgroundTasks
|
||||
from redis import asyncio as aioredis
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
async def add_stream(data: dict):
|
||||
# redis = await aioredis.Redis(host="127.0.0.1", port=7019, password="SMHdFrlK")
|
||||
redis = await aioredis.Redis(host="127.0.0.1")
|
||||
await redis.lpush("hik-sub-event", json.dumps(data))
|
||||
await redis.close()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
|
||||
@app.post("/eventRcv")
|
||||
async def event_rcv(data: dict, background_tasks: BackgroundTasks):
|
||||
background_tasks.add_task(add_stream, data)
|
||||
return {"msg": "success"}
|
||||
|
||||
|
||||
def run_app():
|
||||
uvicorn.run(app=app, host="0.0.0.0", port=8000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_app()
|
Reference in New Issue
Block a user