現象
CACHE_DRIVERとSESSION_DRIVERをどちらもredis
にしたうえで
$ php artisan cache:clear
したところセッションが消えてこまった
原因
CacheとSessionで使っているRedisのDBが同じだから
対策
Cache用のDBと、Session用のDBを分けてやればよい
具体例
config/database.php でセッション用のredisの接続を定義して
config/session.php でその接続を指定するようにしました
config/database.php
...
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'session' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 1,
],
],
...
config/session.php
...
/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/
'connection' => 'session',
...