使用Redis作为Laravel 5.3的会话管理的方法
请参考。
-
- 公式マニュアル
Laravel 5.3 Redis
Laravel 5.3 セッション
安裝步驟
安装predis/predis包。
コンソールで下記を実行
cd /your/project/path
composer require predis/predis
添加Redis服务器的配置
-
- config/database.phpの「Redis Databases」の情報を変更。
実際には下記のようになっているので、.env.xxxxxファイルを変更。
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’ => [
‘cluster’ => false,
‘default’ => [
‘host’ => env(‘REDIS_HOST’, ‘localhost’),
‘password’ => env(‘REDIS_PASSWORD’, null),
‘port’ => env(‘REDIS_PORT’, 6379),
‘database’ => 0,
],
],
.env.xxxxxを編集。
env.xxxxx
REDIS_HOST=(your_redis_host)
REDIS_PASSWORD=(your_redis_password)
REDIS_PORT=6379
更改会话驱动程序
-
- config/sessions.phpの「Default Session Driver」を変更
実際には下記のようになっているので、.envファイルを変更。
config/sessions.php
/*
|————————————————————————–
| Default Session Driver
|————————————————————————–
|
| This option controls the default session “driver” that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: “file”, “cookie”, “database”, “apc”,
| “memcached”, “redis”, “array”
|
*/
‘driver’ => env(‘SESSION_DRIVER’, ‘file’),
.env.xxxxxを編集。
env.xxxxx
SESSION_DRIVER=redis
附言。
- AP<->DB構成の場合、こんなことでハマってしまった…。