Skip to content

Commit b3658be

Browse files
committed
feat: add endpoint to retrieve active session count from Redis
- Implemented a new GET endpoint `/count` to return the number of active sessions stored in Redis. - The endpoint requires authentication and returns a dictionary with the active session count and a message. - Integrated Redis client to facilitate session counting.
1 parent e88e22e commit b3658be

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/routers/user.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dotenv import load_dotenv
77

88
from dependencies import SessionData, require_auth
9+
from config import redis_client
910

1011
load_dotenv()
1112

@@ -39,3 +40,19 @@ async def get_user_info(auth: SessionData = Depends(require_auth), request: Requ
3940
posthog.identify(distinct_id=decoded["sub"], properties=telemetry)
4041

4142
return user_data
43+
44+
@user_router.get("/count")
45+
async def get_user_count(auth: SessionData = Depends(require_auth)):
46+
"""
47+
Get the count of active sessions in Redis
48+
49+
Returns:
50+
dict: A dictionary containing the count of active sessions
51+
"""
52+
# Count keys that match the session pattern
53+
session_count = len(redis_client.keys("session:*"))
54+
55+
return {
56+
"active_sessions": session_count,
57+
"message": f"There are currently {session_count} active sessions in Redis"
58+
}

0 commit comments

Comments
 (0)