1. 程式人生 > >yii2用redis儲存session

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,
            ],