How would you implement logout on every device without scanning Redis?
After this you can answer: How would you implement logout on every device without scanning Redis?
Say it in 30 seconds
Section titled “Say it in 30 seconds”The deeper answer
Section titled “The deeper answer”Creation writes the session and index entry in one Redis script, sets their expiry and removes the oldest session if the user exceeds twenty. Revocation reads only that user’s index. Its cost depends on the device cap, rather than the number of users in the system.
Session reads also verify index membership. If memory eviction removes an index, surviving session records fail closed. That reduces the risk of orphaned session records remaining usable, but it can log users out unexpectedly because sessions share the cache store.
Atomic means Redis commands cannot interleave inside the script. It does not create a transaction across Postgres, Redis and a request already running in another process. For a stronger security event, I would define whether new logins must be blocked and whether sensitive operations need a fresh authorization check.
Counter-questions
Section titled “Counter-questions”Why hash the session identifier?
What if Redis fails midway through the request?
Would a user session version be simpler?
Where in MiniTickets
Section titled “Where in MiniTickets”Read Auth sessions, then inspect the sessions piece →.
apps/api/src/queries/sessions.ts → revokeAllRead this book online: https://book.theversehub.in/