Blogger Information
Blog 142
fans 5
comment 0
visits 130040
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Laravel如何使用Redis共享Session
php开发大牛
Original
511 people have browsed it

一、当系统的访问量上升的时候,使用Redis保存Session可以提高系统的性能,同时也方便多机负载的时候共享Session

1.打开config/database.php。在redis中增加session的连接

 'session' => [
   'host' => env('REDIS_HOST', '127.0.0.1'),
   'password' => env('REDIS_PASSWORD', null),
   'port' => env('REDIS_PORT', 6379),
   'database' => 10,
 ],

2.打开config/session.php ,填入上面的redis连接

'connection' => 'session',

3.修改env 使用redis存取Sessoin

SESSION_DRIVER=redis

现在访问系统。已经使用redis保存session了。大约15%的性能提升(目前的项目)

二、redis 访问配置, 为了使用其它的服务器能访问到redis需要配置redis远程访问

1.打开/etc/redis.conf 修改bind 信息,如当前服务器局域网IP为10.0.0.2

bind 127.0.0.1 10.0.0.2

2.修改 protected-mode

protected-mode no

3.重新加载redis配置

service redis-server reload

4.注册检查iptable是否打开了6379端口访问

iptables -I INPUT -s 10.0.0.2 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

5.其它服务器修改 env

REDIS_HOST=10.0.0.2

现在其它的服务器可以访问redis服务器了。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post