bscheshirwork/yii2-redis-session

Yii2 session based on Redis, can separate session by user

Installs: 15 082

Dependents: 0

Suggesters: 0

Security: 0

Stars: 16

Watchers: 3

Forks: 7

Open Issues: 1

Type:yii2-extension

dev-master 2018-01-30 10:18 UTC

This package is auto-updated.

Last update: 2024-11-08 08:20:08 UTC


README

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
       ],
   ],
]

Installation

Add

    "bscheshirwork/yii2-redis-session": "*@dev",

into your composer.json require section.

Functional

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();

Tests

See this (ru) guide for create PHPUnit suite