feat: add support for tagging + SessionCollection #94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 idctx.session.tagged(userId)-> Get all session IDs for the given user idctx.session.destroySession(sessionId)-> Destroys the given sessionctx.session.getSession(sessionId)-> Get the given session by its idAnd basically, the same methods for SessionCollection
sessionCollection.tag(sessionId, userId)-> Tag the given session with the given user idsessionCollection.tagged(userId)-> Get all session IDs for the given user idsessionCollection.destroySession(sessionId)- Destroys the given sessionsessionCollection.getSession(sessionId)-> Get the given session by its idTagging 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_idcolumn.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 whentagged()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 ofgcProbabilityfor it, like we did in #93. But yeah honestly i think its fine like that, lemme know what do you think !