yii2用redis存储session

今天开发一个后台, 需要用redis来存储用户的session信息,然而redis总是存不住session_id, { SESSIONREDIS_SESSION.session_id() }, 后来发现 ,当你在 php.ini里 已经配置好了连接方式后,

Yii2的配置里其实是不需要再加的。

[Session]

;session.save_handler = files
;session.save_path = "/tmp"
session.save_handler = redis
session.save_path = "tcp://10.20.11.22:6051?auth=redistest6051"
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =

 当已经配置好上面的代码,下面的代码是不需要yii2的配置里加的

'session' => [ //当服务器
            'name' => 'advanced-frontend',
            'class' => 'yii\redis\Session',
            'redis' => [
                'hostname' => '10.20.54.50',
                'port' => 6051,
                'password' => 'redistest6051',
                'database' => 0,
            ],

你可能感兴趣的:(php,php,redis,session)