Redis
View on GitHubSessions on Redis
With SESSION_DRIVER=database the Security page lists the sessions table. Redis
stores one opaque payload per session id and cannot be searched by user, so
App\Support\Sessions\SessionRegistry keeps a per-user map next to it.
How it works
EnforceSessionLifetimeregisters the current session (touch) after it stampslast_activity_at, at most once everySessionRegistry::TOUCH_INTERVALseconds, and immediately for a new session id (after login).UserRepository::getUserSessions,deleteSessionanddeleteOtherSessionsuse the registry whenSessionRegistry::enabled()(theredis,memcachedanddynamodbdrivers) and the table otherwise.- A session counts as signed in only while its payload still exists, so expired and revoked sessions drop out when the list is read. Revoking destroys the payload, so that device is signed out on its next request.
AuthenticatedSessionController::destroyforgets the session on logout.
Adding another session consumer
Read and revoke sessions through UserRepository, never DB::table('sessions')
directly: that table is empty under Redis.
Tests
tests/Feature/Support/SessionRegistryTest.php exercises the registry against an
in-memory session handler; the middleware, logout and repository wiring have
their own tests next to the code they cover.
