Yii2的Cache和Session,以及Redis都使用相同的配置,使用过程中会不会冲突?

文档问题 · ycjnx · 于 5年前 发布 · 2502 次阅读

Fecshop 初始配置 http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-about-config.html

	// Redis的配置
		'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => '127.0.0.1',    // redis的host
            'port' => 6379,               // redis的端口     
			//'password'  => 'xxxxx', // redis的密码
            'database' => 0,    // redis的库,此处不要改动
        ],
        // Cache 组件的配置,您需要配置下面的redis
        'cache' => [
            'class'     => 'yii\redis\Cache',
            // 缓存配置独立的redis,您可以和上面的redis配置一致
            'redis' => [
                'hostname' => '127.0.0.1',   // redis的host
                'port' => 6379,              // redis的端口   
                //'password'  => 'xxxxx', // redis的密码
            ],
        ],
        // Session 组件的配置,您需要配置下面的redis
        'session' => [
            'class'   => 'yii\redis\Session',
            // session过期时间,1天过期
            'timeout' => 86400 * 1, 
            // 缓存配置独立的redis,您可以和上面的redis配置一致
            'redis' => [
                'hostname' => '127.0.0.1', // redis的host
                'port' => 6379,            // redis的端口   
                //'password'  => 'xxxxx', // redis的密码
            ],
        ],
共收到 3 条回复 fecshop
Fecmall#15年前 0 个赞

不会,虽然理论上会,如果你实在担心,可以设置database,这样,如果每个入口的cache和session都需要设置

另外redis默认的库数量有限制,好像是16个,如果不够,可以通过配置更改

ycjnx#25年前 0 个赞

谢谢老大!

Fecmall#35年前 0 个赞

@ycjnx #2楼 yii是懒加载,容器注入模式,同一个class,通过容器注入不同的配置,得到不同的对象

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics