yii2 redis和session使用
2018-12-13 本文已影响0人
我的楼兰0909
项目根目录:composer require yiisoft/yii2-redis
composer.json中声明依赖:"yiisoft/yii-redis": "~2.0.0"
composer update
config/web.php中添加
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
];
使用
$redis = Yii::$app->redis;
$redis->set('xiaogang','gasssssssss');
$value = $redis->get('xiaogang');
echo $value;exit;
session使用
$session = Yii::$app->session;
$session->open();
//$session->close();
* open
* close
* set
* get
* has
* remove
* count
* removeAll
*/
//遍历所有的session变量
foreach ($session as $key=>$value) {
echo $key.'<br>';
}
$session['captcha'] = [
'number' => 5,
'lifetime' => 3600,
];
echo $session['captcha']['lifetime'];
var_dump($session['captcha']);