Skip to content

Conversation

@Julien-R44
Copy link
Member

@Julien-R44 Julien-R44 commented Dec 10, 2025

Close #92

Add session tagging support, allowing sessions to be linked to user ids + SessionCollection API

New APIs:

  • ctx.session.tag(userId) -> Tag the current session with the given user id
  • ctx.session.tagged(userId) -> Get all session IDs for the given user id
  • ctx.session.destroySession(sessionId) -> Destroys the given session
  • ctx.session.getSession(sessionId) -> Get the given session by its id

And basically, the same methods for SessionCollection

  • sessionCollection.tag(sessionId, userId) -> Tag the given session with the given user id
  • sessionCollection.tagged(userId) -> Get all session IDs for the given user id
  • sessionCollection.destroySession(sessionId) - Destroys the given session
  • sessionCollection.getSession(sessionId) -> Get the given session by its id

Tagging is only supported by Redis, database, and memory => If calling those methods with another driver we throw an error
DB implementation is standard, we add a nullable index_id column.
Redis implementation: we uses a SET per user (session_tag:{userId}) to store session ids. One important thing to note is, expired sessions are lazily cleaned up when tagged() is called. Which is not ideal, but tbh I think its fine, probably more than negligible. Another approach could be to also have some sort of gcProbability for it, like we did in #93. But yeah honestly i think its fine like that, lemme know what do you think !

@thetutlage
Copy link
Member

Should we have the following methods?

  • ctx.session.tagged(userId) -> Get all session IDs for the given user id
  • ctx.session.destroySession(sessionId) -> Destroys the given session
  • ctx.session.getSession(sessionId) -> Get the given session by its id

The ctx.session is bound to a given session id and it shouldn't really have APIs to act on other session ids, that is what the collection will do.

Also, if I look at it practically, we will only call ctx.session.tag to tag the current session with the logged-in user and never reach for other methods. They will always be accessed via the SessionCollection.

@Julien-R44
Copy link
Member Author

agreed, very right. i actually hesitated to add them and ended up doing it just for consistency. But yeah, its indeed a bit weird to be able to call getSession from ctx.session ..

methods have been removed
Also about "Should we return just the ids or the entire session objects?" => totally fair point. updated that as well !

@Julien-R44 Julien-R44 merged commit a51e388 into 7.x Dec 17, 2025
20 checks passed
@Julien-R44 Julien-R44 deleted the feat/tagging-support branch December 17, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session collection

3 participants