How Laravel uses Redis to share Session, laravelredis
1. When the system traffic increases, using Redis to save sessions can improve the system performance and facilitate Session sharing when multiple hosts are loaded.
1. Open config/database. php. Add session connections in redis
'session' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 10, ],
2. Open config/session. php and fill in the above redis connection
'connection' => 'session',
3. Modify env to use redis to access Sessoin
SESSION_DRIVER=redis
Access the system now. You have used redis to save the session. Performance Improvement of approximately 15% (current project)
Ii. redis access configuration. To use other servers to access redis, You need to configure redis remote access.
1. Enable/etc/redis. conf to modify the bind information. For example, the current server lan ip address is 10.0.0.2.
bind 127.0.0.1 10.0.0.2
2. Modify protected-mode
protected-mode no
3. Reload redis Configuration
service redis-server reload
4. Check whether port 6379 is enabled for iptable Registration
iptables -I INPUT -s 10.0.0.2 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
5. Modify env on other servers
REDIS_HOST=10.0.0.2
Now other servers can access the redis server.
Summary
The above section describes how Laravel uses Redis to share sessions. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!