1:配置文件 修改php.ini文件永久修改
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6388"
;如有密码设置auth参数
;session.save_path = "tcp://127.0.0.1:6388?auth=123456"
2:使用ini_set函数临时设置
ini_set("session.save_handler", "redis");
ini_set("session.save_path", "tcp://127.0.0.1:6388?auth=123456");
3:yii2 使用redis 存session配置
下载yii2-redis组件
composer require yiisoft/yii2-redis:"~2.0.0"
修改配置文件main-local.php配置session组件
'session'=>[
'class' => 'yii\redis\Session',
'redis' => [
'hostname' => 127.0.0.1',
'port' => 6388,
'password' => '123',
'database' =>1,
],
],
配置多个二级域名共享session可增加以下相关配置
'session'=>[
'class' => 'yii\redis\Session',
'timeout'=>3600,
'keyPrefix'=>'sessionkey', //指定session前缀否则域名不同不匹配
'cookieParams' => [
'path' => '/',
'domain' => ".redis.cc", //两个站点的配置需要一致,这里设置的是一级域名
],
'redis' => [
'hostname' => 127.0.0.1',
'port' => 6388,
'password' => '123',
'database' =>1,
],
],