Laravel 使用 Redis 作为 session 驱动

安装Redis

composer require predis/predis

设置Redis连接

config/database.php

'redis' => [

'client' => 'predis',

'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'redis-session' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],

],

设置session驱动器

config/session.php

//session 驱动方式为 redis
'driver' => env('SESSION_DRIVER', 'redis'),

//设置redis驱动器的连接配置,即:config/database.php中redis数组中的配置信息
'connection' => 'redis-session',

修改.env文件

SESSION_DRIVER=redis

OK。

0%