Based on yii2-redis session. Can remove user's sessions by user identity id. Can get a online users.
Redis Session implements a session component using redis as the storage medium.
Redis Session requires redis version 3.0.2 or higher to work properly.
It needs to be configured with a redis [[Connection]] that is also configured as an application component.
By default it will use the redis
application component (see yii2-redis for more info).
[
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
]
]
To use redis Session as the session application component, configure the application as follows,
[
'components' => [
'session' => [
'class' => 'bscheshirwork\redis\Session',
// 'redis' => 'redis' // id of the connection application component
],
],
]
Add
"bscheshirwork/yii2-redis-session": "*@dev",
into your composer.json
require
section.
Get all online user's
\Yii::$app->session->getOnlineUsers();
Get all active session by user
\Yii::$app->session->getSessionsById($userIdentityId);
Remove all active session by user
\Yii::$app->session->destroyUserSessions($userIdentityId);
Get all active sessions
\Yii::$app->session->getActiveSessions();
See this (ru) guide for create PHPUnit suite