2017-09-12 12 views
0

こんにちは皆私は、私のlaravelアプリケーションのセッションをlocalhostにredisで保存したい、redis-serverは実行中です。昨日私はRedis :: set( 'key')などを試してみました。このエラーにつながります - > Redis connection [redis]は設定されていません。Laravel-Session-StorageをRedisにセットアップする方法は?

マイ.envファイル:

BROADCAST_DRIVER=pusher 
CACHE_DRIVER=file 
SESSION_DRIVER=redis 
QUEUE_DRIVER=sync 

REDIS_HOST=127.0.0.1 
REDIS_PASSWORD=null 
REDIS_PORT=6379 

私のconfig/session.phpファイル

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | 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', 'redis'), 


    /* 
    |-------------------------------------------------------------------------- 
    | Session Lifetime 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify the number of minutes that you wish the session 
    | to be allowed to remain idle before it expires. If you want them 
    | to immediately expire on the browser closing, set that option. 
    | 
    */ 

    'lifetime' => 120, 

    'expire_on_close' => true, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Encryption 
    |-------------------------------------------------------------------------- 
    | 
    | This option allows you to easily specify that all of your session data 
    | should be encrypted before it is stored. All encryption will be run 
    | automatically by Laravel and you can use the Session like normal. 
    | 
    */ 

    'encrypt' => false, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session File Location 
    |-------------------------------------------------------------------------- 
    | 
    | When using the native session driver, we need a location where session 
    | files may be stored. A default has been set for you but a different 
    | location may be specified. This is only needed for file sessions. 
    | 
    */ 

    'files' => storage_path('framework/sessions'), 

    /* 
    |-------------------------------------------------------------------------- 
    | 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' => 'redis', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Database Table 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "database" session driver, you may specify the table we 
    | should use to manage the sessions. Of course, a sensible default is 
    | provided for you; however, you are free to change this as needed. 
    | 
    */ 

    'table' => 'sessions', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cache Store 
    |-------------------------------------------------------------------------- 
    | 
    | When using the "apc" or "memcached" session drivers, you may specify a 
    | cache store that should be used for these sessions. This value must 
    | correspond with one of the application's configured cache stores. 
    | 
    */ 

    'store' => null, 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Sweeping Lottery 
    |-------------------------------------------------------------------------- 
    | 
    | Some session drivers must manually sweep their storage location to get 
    | rid of old sessions from storage. Here are the chances that it will 
    | happen on a given request. By default, the odds are 2 out of 100. 
    | 
    */ 

    'lottery' => [2, 100], 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Name 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the name of the cookie used to identify a session 
    | instance by ID. The name specified here will get used every time a 
    | new session cookie is created by the framework for every driver. 
    | 
    */ 

    'cookie' => 'laravel_session', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Path 
    |-------------------------------------------------------------------------- 
    | 
    | The session cookie path determines the path for which the cookie will 
    | be regarded as available. Typically, this will be the root path of 
    | your application but you are free to change this when necessary. 
    | 
    */ 

    'path' => '/', 

    /* 
    |-------------------------------------------------------------------------- 
    | Session Cookie Domain 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may change the domain of the cookie used to identify a session 
    | in your application. This will determine which domains the cookie is 
    | available to in your application. A sensible default has been set. 
    | 
    */ 

    'domain' => env('SESSION_DOMAIN', null), 

    /* 
    |-------------------------------------------------------------------------- 
    | HTTPS Only Cookies 
    |-------------------------------------------------------------------------- 
    | 
    | By setting this option to true, session cookies will only be sent back 
    | to the server if the browser has a HTTPS connection. This will keep 
    | the cookie from being sent to you if it can not be done securely. 
    | 
    */ 

    'secure' => env('SESSION_SECURE_COOKIE', false), 

    /* 
    |-------------------------------------------------------------------------- 
    | HTTP Access Only 
    |-------------------------------------------------------------------------- 
    | 
    | Setting this value to true will prevent JavaScript from accessing the 
    | value of the cookie and the cookie will only be accessible through 
    | the HTTP protocol. You are free to modify this option if needed. 
    | 
    */ 

    'http_only' => true, 

]; 

私のconfig/database.phpでファイル

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Database Connection Name 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify which of the database connections below you wish 
    | to use as your default connection for all database work. Of course 
    | you may use many connections at once using the Database library. 
    | 
    */ 

    'default' => env('DB_CONNECTION', 'mysql'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Database Connections 
    |-------------------------------------------------------------------------- 
    | 
    | Here are each of the database connections setup for your application. 
    | Of course, examples of configuring each database platform that is 
    | supported by Laravel is shown below to make development simple. 
    | 
    | 
    | All database work in Laravel is done through the PHP PDO facilities 
    | so make sure you have the driver for your particular database of 
    | choice installed on your machine before you begin development. 
    | 
    */ 

    'connections' => [ 

     'sqlite' => [ 
      'driver' => 'sqlite', 
      'database' => env('DB_DATABASE', database_path('database.sqlite')), 
      'prefix' => '', 
     ], 

     'mysql' => [ 
      'driver' => 'mysql', 
      'host' => env('DB_HOST', '127.0.0.1'), 
      'port' => env('DB_PORT', '3306'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'unix_socket' => env('DB_SOCKET', ''), 
      'charset' => 'utf8mb4', 
      'collation' => 'utf8mb4_unicode_ci', 
      'prefix' => '', 
      'strict' => true, 
      'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', 
     ], 

     'pgsql' => [ 
      'driver' => 'pgsql', 
      'host' => env('DB_HOST', '127.0.0.1'), 
      'port' => env('DB_PORT', '5432'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'prefix' => '', 
      'schema' => 'public', 
      'sslmode' => 'prefer', 
     ], 

     'sqlsrv' => [ 
      'driver' => 'sqlsrv', 
      'host' => env('DB_HOST', 'localhost'), 
      'port' => env('DB_PORT', '1433'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'prefix' => '', 
     ], 

     'redis' => [ 
      'client' => 'predis', 
      'cluster' => false, 
      'default' => [ 
       'host' => env('REDIS_HOST', '127.0.0.1'), 
       'password' => env('REDIS_PASSWORD', null), 
       'port' => env('REDIS_PORT', 6379), 
       'database' => 0, 
      ], 
     ], 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Migration Repository Table 
    |-------------------------------------------------------------------------- 
    | 
    | This table keeps track of all the migrations that have already run for 
    | your application. Using this information, we can determine which of 
    | the migrations on disk haven't actually been run in the database. 
    | 
    */ 

    'migrations' => 'migrations', 

    /* 
    |-------------------------------------------------------------------------- 
    | 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', 
     'cluster' => false, 
     'default' => [ 
      'host' => env('REDIS_HOST', '127.0.0.1'), 
      'password' => env('REDIS_PASSWORD', null), 
      'port' => env('REDIS_PORT', 6379), 
      'database' => 0, 
     ], 
    ], 
]; 

私は/カットを削除した場合database.phpファイル内の 'redis'のうちの1つでもまだ動作しません。あるいは、次のエラーが発生します:array_key_exists()は、パラメータ2が配列nullになることを想定しています。私は

は、任意のヘルプやアイデアをありがとうございました...私が間違ってやっていることは、セットアップに懸命のRedisのために/と3つのファイルであることができなかったのか分からないLaravelのマニュアルに従っ:)

+0

私はsession.php以内に変更する場合: '接続' => 'のRedis' から 'コネクション' => TO [=> env( 'REDIS_HOST'、 '127.0.0.1')、 'パスワード' => env( 'REDIS_PASSWORD'、null)、 'ポート' => env( 'REDIS_PORT'、6379)、 'データベース' => 0、 ]、 Iは、次のエラーを取得: を "(1/1)ErrorException 不正オフセット型 ISSETまたは空にRedisManager.phpにおいて(ライン78)" – CodingForEver

+0

削除Redisの接続アレイからと次に試してみてください。 –

+0

ありがとうJamal Abdul Nasir、私は 'connection' => 'redis'を 'connection' => nullに変更しました。 :) – CodingForEver

答えて

0

設定/ session.php

'driver' => env('SESSION_DRIVER', 'redis'), 
'connection' => 'default', 

のconfig/database.phpで

return [ 
    ... 
    'redis' => [ 
     'cluster' => false, 
     'default' => [ 
      'host' => env('REDIS_HOST', 'localhost'), 
      'password' => env('REDIS_PASSWORD', null), 
      'port' => env('REDIS_PORT', 6379), 
      'database' => 0, 
     ], 

    ], 
]; 
関連する問題