remove redis stuff again because v2 of fastapi_limiter doesn't need it anymore
This commit is contained in:
+1
-9
@@ -8,7 +8,6 @@ services:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- mariadb
|
||||
- redis
|
||||
env_file: ".env"
|
||||
|
||||
mariadb:
|
||||
@@ -23,12 +22,5 @@ services:
|
||||
volumes:
|
||||
- mariadb_data:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: valkey/valkey:9
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
volumes:
|
||||
mariadb_data:
|
||||
redis_data:
|
||||
mariadb_data:
|
||||
+1
-9
@@ -8,7 +8,6 @@ services:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- mariadb
|
||||
- redis
|
||||
env_file: ".env"
|
||||
|
||||
mariadb:
|
||||
@@ -23,12 +22,5 @@ services:
|
||||
volumes:
|
||||
- mariadb_data:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: valkey/valkey:9
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
volumes:
|
||||
mariadb_data:
|
||||
redis_data:
|
||||
mariadb_data:
|
||||
@@ -1,9 +1,9 @@
|
||||
import aiohttp
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi_limiter import FastAPILimiter
|
||||
from fastapi import Depends, FastAPI
|
||||
from pyrate_limiter import Duration, Limiter, Rate
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
import redis.asyncio as redis
|
||||
from fastapi import Depends
|
||||
import asyncmy
|
||||
import asyncio
|
||||
@@ -43,8 +43,6 @@ async def connect_db(app: FastAPI):
|
||||
maxsize=20
|
||||
)
|
||||
await create_tables(app.state.pool)
|
||||
redis_client = await redis.from_url("redis://localhost")
|
||||
await FastAPILimiter.init(redis_client)
|
||||
task = asyncio.create_task(fetch_images())
|
||||
try:
|
||||
yield
|
||||
@@ -56,10 +54,9 @@ async def connect_db(app: FastAPI):
|
||||
pass
|
||||
app.state.pool.close()
|
||||
await app.state.pool.wait_closed()
|
||||
await FastAPILimiter.close()
|
||||
await redis_client.close()
|
||||
|
||||
app = FastAPI(lifespan=connect_db)
|
||||
limiter = Limiter(Rate(50, Duration.MINUTE))
|
||||
|
||||
async def create_tables(pool):
|
||||
async with pool.acquire() as conn:
|
||||
@@ -79,7 +76,7 @@ async def create_tables(pool):
|
||||
async def root():
|
||||
return {"message": "yes the api works, maybe i will create a small landing page later here"}
|
||||
|
||||
@app.get("/random", dependencies=[Depends(RateLimiter(times=25, seconds=60))])
|
||||
@app.get("/random", dependencies=[Depends(RateLimiter(limiter=limiter))])
|
||||
async def get_random_bnuy(request: Request):
|
||||
async with app.state.pool.acquire() as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
@@ -94,7 +91,7 @@ async def get_random_bnuy(request: Request):
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="No available images found")
|
||||
|
||||
@app.get("/images/{filename}", dependencies=[Depends(RateLimiter(times=25, seconds=60))])
|
||||
@app.get("/images/{filename}", dependencies=[Depends(RateLimiter(limiter=limiter))])
|
||||
async def get_image(filename: str):
|
||||
async with app.state.pool.acquire() as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
fastapi[standard]
|
||||
fastapi_limiter
|
||||
asyncmy
|
||||
aiohttp
|
||||
redis
|
||||
aiohttp
|
||||
Reference in New Issue
Block a user