How to setup Laravel-Session-Storage to Redis? -
hi want store session's of laravel app in redis on localhost, redis-server running, yesterday tried redis::set('key') , on , worked storeing session in redis leads error -> redis connection [redis] not configured.
my .env-file:
broadcast_driver=pusher cache_driver=file session_driver=redis queue_driver=sync redis_host=127.0.0.1 redis_password=null redis_port=6379
my config/session.php file
<?php return [ /* |-------------------------------------------------------------------------- | default session driver |-------------------------------------------------------------------------- | | option controls default session "driver" used on | requests. default, use lightweight native driver | may specify of other wonderful drivers provided here. | | supported: "file", "cookie", "database", "apc", | "memcached", "redis", "array" | */ 'driver' => env('session_driver', 'redis'), /* |-------------------------------------------------------------------------- | session lifetime |-------------------------------------------------------------------------- | | here may specify number of minutes wish session | allowed remain idle before expires. if want them | expire on browser closing, set option. | */ 'lifetime' => 120, 'expire_on_close' => true, /* |-------------------------------------------------------------------------- | session encryption |-------------------------------------------------------------------------- | | option allows specify of session data | should encrypted before stored. encryption run | automatically laravel , can use session normal. | */ 'encrypt' => false, /* |-------------------------------------------------------------------------- | session file location |-------------------------------------------------------------------------- | | when using native session driver, need location session | files may stored. default has been set different | location may specified. needed file sessions. | */ 'files' => storage_path('framework/sessions'), /* |-------------------------------------------------------------------------- | session database connection |-------------------------------------------------------------------------- | | when using "database" or "redis" session drivers, may specify | connection should used manage these sessions. should | correspond connection in database configuration options. | */ 'connection' => 'redis', /* |-------------------------------------------------------------------------- | session database table |-------------------------------------------------------------------------- | | when using "database" session driver, may specify table | should use manage sessions. of course, sensible default | provided you; however, free change needed. | */ 'table' => 'sessions', /* |-------------------------------------------------------------------------- | session cache store |-------------------------------------------------------------------------- | | when using "apc" or "memcached" session drivers, may specify | cache store should used these sessions. value must | correspond 1 of application's configured cache stores. | */ 'store' => null, /* |-------------------------------------------------------------------------- | session sweeping lottery |-------------------------------------------------------------------------- | | session drivers must manually sweep storage location | rid of old sessions storage. here chances | happen on given request. default, odds 2 out of 100. | */ 'lottery' => [2, 100], /* |-------------------------------------------------------------------------- | session cookie name |-------------------------------------------------------------------------- | | here may change name of cookie used identify session | instance id. name specified here used every time | new session cookie created framework every driver. | */ 'cookie' => 'laravel_session', /* |-------------------------------------------------------------------------- | session cookie path |-------------------------------------------------------------------------- | | session cookie path determines path cookie | regarded available. typically, root path of | application free change when necessary. | */ 'path' => '/', /* |-------------------------------------------------------------------------- | session cookie domain |-------------------------------------------------------------------------- | | here may change domain of cookie used identify session | in application. determine domains cookie | available in application. sensible default has been set. | */ 'domain' => env('session_domain', null), /* |-------------------------------------------------------------------------- | https cookies |-------------------------------------------------------------------------- | | setting option true, session cookies sent | server if browser has https connection. keep | cookie being sent if can not done securely. | */ 'secure' => env('session_secure_cookie', false), /* |-------------------------------------------------------------------------- | http access |-------------------------------------------------------------------------- | | setting value true prevent javascript accessing | value of cookie , cookie accessible through | http protocol. free modify option if needed. | */ 'http_only' => true, ];
my config/database.php file
<?php return [ /* |-------------------------------------------------------------------------- | default database connection name |-------------------------------------------------------------------------- | | here may specify of database connections below wish | use default connection database work. of course | may use many connections @ once using database library. | */ 'default' => env('db_connection', 'mysql'), /* |-------------------------------------------------------------------------- | database connections |-------------------------------------------------------------------------- | | here each of database connections setup application. | of course, examples of configuring each database platform | supported laravel shown below make development simple. | | | database work in laravel done through php pdo facilities | make sure have driver particular database of | choice installed on machine before 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 |-------------------------------------------------------------------------- | | table keeps track of migrations have run | application. using information, can determine of | migrations on disk haven't been run in database. | */ 'migrations' => 'migrations', /* |-------------------------------------------------------------------------- | redis databases |-------------------------------------------------------------------------- | | redis open source, fast, , advanced key-value store | provides richer set of commands typical key-value systems | such apc or memcached. laravel makes easy 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, ], ], ];
if delete/cut 1 of 'redis' within database.php file still doesn't work or following error:array_key_exists() expects parameter 2 array null given. followed laravel documentation don't know i'm doing wrong couldn't hard setup 3 files with/for redis ...
thank or ideas :)
Comments
Post a Comment