The package implements the SessionHandlerInterface using the PSR-16 cache for storage.
See also:
- YII3-CACHE-REDIS - The package provides the Redis handler and implements the PSR-16 cache using the Redis PHP extension
- PHP 8.1 or higher.
composer require klsoft/yii3-cache-session-handlerExample:
use Yiisoft\Session\SessionInterface;
use Yiisoft\Session\Session;
use Klsoft\Yii3CacheSessionHandler\SessionHandler;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Cache\Cache;
use Klsoft\Yii3CacheRedis\RedisCache;
return [
// ...
SessionInterface::class => [
'class' => Session::class,
'__construct()' => [
'options' => $params['session']['options'] ?? [],
'handler' => new SessionHandler(
new RedisCache(
new Redis([
'host' => $params['redisHost'],
'port' => $params['redisPort'],
'database' => $params['redisDatabaseSession']
])
)
)
]
],
CacheInterface::class => [
'class' => Cache::class,
'__construct()' => [
'handler' => new RedisCache(
new Redis([
'host' => $params['redisHost'],
'port' => $params['redisPort'],
'database' => $params['redisDatabaseCache']
])
)
]
],
];