Laravel Redis Session Driver Does Not Work

I'm having difficulty using the larvel 4 "redis" session driver. The problem is that virtually nothing is saved.

Things I checked:

  • I installed the driver in redis in the session configuration file and cache configuration file
  • The database configuration file indicates the database configuration for redis:
  • I tried saving something manually using a redis class that really worked, storage with the session class didn't work

     // this is in my session config 'driver' => 'redis', //this is my db-config 'redis' => array( 'cluster' => true, 'default' => array( 'host' => '127.0.0.1', 'port' => 6379, 'database' => 0, ), ), //this works $redis = Redis::connection(); $redis->set('name', 'Taylor'); //this doesn't work Session::put('name', 'Taylor'); 

When I change the session to native , it works

Any help would be appreciated

UPDATE
This is interesting: When I use redis-cli monitor , as suggested by @philo, I get some output when trying to enter my L4 application:

 `1387191809.513730 [0 127.0.0.1:59268] "SELECT" "0" 1387191809.513835 [0 127.0.0.1:59268] "GET" "laravel:siau639prmckja34le11vbsfl7" 1387191809.863851 [0 127.0.0.1:59268] "SET" "laravel:siau639prmckja34le11vbsfl7" "s:226:\"_sf2_attributes|a:2:{s:6:\"_token\";s:40:\"9LPf354C2ZNtw0Oc1zyafSvMdFFlspPiJsq8w90v\";s:5:\"flash\";a:2:{s:3:\"old\";a:0:{}s:3:\"new\";a:0:{}}}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:\"u\";i:1387191809;s:1:\"c\";i:1387191809;s:1:\"l\";s:1:\"0\";}\";" 1387191809.866655 [0 127.0.0.1:59268] "EXPIRE" "laravel:siau639prmckja34le11vbsfl7" "0" 1387191828.464840 [0 127.0.0.1:59279] "SELECT" "0" 1387191828.464970 [0 127.0.0.1:59279] "GET" "laravel:siau639prmckja34le11vbsfl7" 1387191828.581774 [0 127.0.0.1:59279] "SET" "laravel:siau639prmckja34le11vbsfl7" "s:599:\"_sf2_attributes|a:4:{s:6:\"_token\";s:40:\"KSkc5OAsp9Psz3MC7dYo6FfkTvcdK6I6HcisSyJ3\";s:10:\"_old_input\";a:3:{s:6:\"_token\";s:40:\"9LPf354C2ZNtw0Oc1zyafSvMdFFlspPiJsq8w90v\";s:8:\"username\";s:10:\"bertcasier\";s:8:\"password\";s:4:\"test\";}s:5:\"flash\";a:2:{s:3:\"new\";a:0:{}s:3:\"old\";a:2:{i:0;s:10:\"_old_input\";i:1;s:6:\"errors\";}}s:6:\"errors\";O:29:\"Illuminate\\Support\\MessageBag\":2:{s:11:\"\x00*\x00messages\";a:1:{s:7:\"general\";a:1:{i:0;s:48:\"Ongeldige gebruikersnaam/wachtwoordcombinatie...\";}}s:9:\"\x00*\x00format\";s:8:\":message\";}}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:\"u\";i:1387191828;s:1:\"c\";i:1387191828;s:1:\"l\";s:1:\"0\";}\";" 1387191828.582214 [0 127.0.0.1:59279] "EXPIRE" "laravel:siau639prmckja34le11vbsfl7" "0" 1387191828.613536 [0 127.0.0.1:59284] "SELECT" "0" 1387191828.613649 [0 127.0.0.1:59284] "GET" "laravel:siau639prmckja34le11vbsfl7" 1387191828.653734 [0 127.0.0.1:59284] "SET" "laravel:siau639prmckja34le11vbsfl7" "s:226:\"_sf2_attributes|a:2:{s:6:\"_token\";s:40:\"SMxXljPLDaViVVSpCohfOKlpByhjp8E2ywS6zVkh\";s:5:\"flash\";a:2:{s:3:\"old\";a:0:{}s:3:\"new\";a:0:{}}}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:\"u\";i:1387191828;s:1:\"c\";i:1387191828;s:1:\"l\";s:1:\"0\";}\";" 1387191828.654102 [0 127.0.0.1:59284] "EXPIRE" "laravel:siau639prmckja34le11vbsfl7" "0" 1387191878.208814 [0 127.0.0.1:59358] "config" "get" "databases" 1387191878.215094 [0 127.0.0.1:59358] "INFO" "keyspace" 1387191880.176125 [0 127.0.0.1:59358] "select" "0" 1387191880.176314 [0 127.0.0.1:59358] "keys" "*"` 

Does my session seem to expire immediately? I wrote a custom Auth User Provider that registers me with a rest-API and saves the result in a session. But when I use the redis session driver, I immediately get redirected to the login page. When I use RDM (redis client GUI), I cannot find session variables

+6
source share
3 answers

I found a solution thanks to @philo's hint.

The session lifetime in my configuration file was set to zero because I want my session to expire when the browser closes. This works for native sessions, but for redis sessions this causes the session to expire immediately. When I change my life time, my session works as expected.

Now I'm still looking for how to expire in the browser close

+6
source

Now I'm still looking for how to expire in the browser close

Please note that cookie lifetime and session data are not related. You want the cookie lifetime to be 0 (delete when you close the browser), and the session data lifetime will be longer (if you allow between requests).

+1
source

You must attach your route to the controller using middlewareGroups - Laravel 5.2

Route :: group (['middlewareGroups' => ['web']], function () {...});

0
source

Source: https://habr.com/ru/post/959321/


All Articles