-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from nazywam/feature/redis-cache
Add optional Redis analysis caching
- Loading branch information
Showing
13 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
from backend.api.endpoints import analyze, submit | ||
from backend.api.endpoints import analyze, submit, lookup | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(analyze.router, prefix="/analyze", tags=["analyze"]) | ||
api_router.include_router(submit.router, prefix="/submit", tags=["submit"]) | ||
api_router.include_router(lookup.router, prefix="/lookup", tags=["lookup"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
|
||
from redis import StrictRedis | ||
from fastapi import APIRouter, HTTPException, status | ||
|
||
from backend.schemas.response import Response | ||
from backend.core.settings import REDIS_HOST, REDIS_PASSWORD | ||
|
||
router = APIRouter() | ||
|
||
@router.get( | ||
"/{identifier}/", | ||
response_description="Return an analysis result", | ||
summary="Lookup cached analysis", | ||
description="Try to fetch existing analysis from database", | ||
status_code=200, | ||
) | ||
async def lookup(identifier: str) -> Response: | ||
if not REDIS_HOST: | ||
raise HTTPException( | ||
status_code=status.HTTP_501_NOT_IMPLEMENTED, | ||
detail="Redis cache is not enabled", | ||
) | ||
|
||
redis_conn = StrictRedis(host=REDIS_HOST, password=REDIS_PASSWORD) | ||
data = redis_conn.hget(identifier, "analysis") | ||
if not data: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Analysis cache not found", | ||
) | ||
|
||
return json.loads(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ class Eml(APIModel): | |
attachments: list[Attachment] | ||
bodies: list[Body] | ||
header: Header | ||
identifier: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
class Response(APIModel): | ||
eml: Eml | ||
verdicts: list[Verdict] | ||
identifier: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters