Skip to content

Commit

Permalink
♻️ improved examples & bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJecksMan committed Feb 23, 2024
1 parent 1c96708 commit 3bfca90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/fastapi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from redis.asyncio import Redis
from random import randint

from fastapi import FastAPI, Request
from fastapi.responses import ORJSONResponse
from redis.asyncio import Redis

from redsession import ServerSessionMiddleware
from redsession.backend import RedisBackend


app = FastAPI(default_response_class=ORJSONResponse)

redis = Redis(host="192.168.1.3")
redis = Redis(host="192.168.1.3", protocol=3)

app.add_middleware(
ServerSessionMiddleware, backend=RedisBackend(redis), secret_key="secret"
Expand All @@ -30,7 +30,7 @@ async def set_session(request: Request):
@app.put("/update_session")
async def update_session(request: Request):
request.session.clear()
request.session.update({"user_id": 2})
request.session.update({"user_id": randint(-100, 100)})
return {"session": request.session}


Expand Down
12 changes: 6 additions & 6 deletions examples/starlette.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from redis.asyncio import Redis
from random import randint

from starlette.routing import Route
from redis.asyncio import Redis
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.applications import Starlette
from starlette.routing import Route

from redsession import ServerSessionMiddleware
from redsession.backend import RedisBackend


redis = Redis(host="192.168.1.3")
redis = Redis(host="192.168.1.3", protocol=3)


async def get_session(request: Request):
Expand All @@ -23,7 +23,7 @@ async def set_session(request: Request):

async def update_session(request: Request):
request.session.clear()
request.session.update({"user_id": 2})
request.session.update({"user_id": randint(-100, 100)})
return JSONResponse({"session": request.session})


Expand Down

0 comments on commit 3bfca90

Please sign in to comment.