17
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel 5.3でセッション管理にredisを使用する方法

Last updated at Posted at 2016-09-14

参照

設定方法

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構成の場合、こんなことでハマってしまった…。
17
20
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?