我在使用laravel 4" redis"会话驱动程序 问题是没有实际存储。
我检查过的事情:
redis
我尝试使用redis-class手动存储内容,确实有效,存储会话类不起作用
// 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');
当我将会话更改为native
时,它可以正常工作
任何帮助将不胜感激
更新
这很有趣:
当我按照@philo的建议使用redis-cli monitor
时,我在尝试登录L4应用程序时会得到一些输出:
`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" "*"`
好像我的会话会立即过期? 我编写了一个自定义Auth用户提供程序,它在rest-API中登录,并将结果存储在会话中。但是当我使用redis会话驱动程序时,我会立即重定向回登录页面。当我使用RDM(redis客户端GUI)时,我无法找到任何会话变量
答案 0 :(得分:6)
我已经找到了解决方案,感谢来自@philo的提示。
我的配置文件中的会话生命周期设置为zero
,因为我希望我的会话在浏览器关闭时到期。这适用于本机会话,但对于redis会话,它会导致会话立即过期。当我改变生命时间时,我的会话按预期工作。
现在我仍在搜索如何在浏览器关闭时过期
答案 1 :(得分:1)
现在我仍在搜索如何在浏览器关闭时过期
请注意,Cookie的生命周期和会话数据不相关。您希望cookie生存期为0(在浏览器关闭时删除),会话数据生命周期更长(只要您允许请求之间)。
答案 2 :(得分:0)
您必须使用中间件组将路径封闭到控制器 - Laravel 5.2
Route :: group(['middlewareGroups'=> ['web']],function(){ ... });