Home >Backend Development >PHP Tutorial >Redis+Nginx+Tomcat realizes session sharing
Resource download
implementation
<code><span>Engine</span><span>name</span>=<span>"Catalina"</span><span>defaultHost</span>=<span>"localhost"</span>>?</code>
If jvmRoute is added, the redis content will take up too much, and jvmRoute will be copied into redis in a loop, causing the memory to be full. As shown below:
<code><span>Valve</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionHandlerValve"</span> /><span>Manager</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionManager"</span><span>host</span>=<span>"192.168.25.132"</span><span>port</span>=<span>"6379"</span><span>database</span>=<span>"0"</span><span>maxInactiveInterval</span>=<span>"60"</span> /></code>
The above method is that the entire Tomcat uses redis to save the Session. We can also add an xml startup project under confCatalinalocalhost. At this time, Use redis for this project alone, such as adding a ROOT.xml, the code is as follows:
<code><span><?xml version='1.0' encoding='utf-8'?></span><span>Context</span><span>path</span>=<span>"/"</span><span>docBase</span>=<span>"F:\learn\tomcat\ewebsite"</span><span>debug</span>=<span>"0"</span><span>privileged</span>=<span>"true"</span>><span>Valve</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionHandlerValve"</span> /><span>Manager</span><span>className</span>=<span>"com.radiadesign.catalina.session.RedisSessionManager"</span><span>host</span>=<span>"192.168.25.132"</span><span>port</span>=<span>"6379"</span><span>database</span>=<span>"0"</span><span>maxInactiveInterval</span>=<span>"60"</span> /><span><span>Context</span>></span></code>
Test
For testing methods, please refer to "Tomcat Cluster and Session Sharing + Nginx Load》
At the same time, check the keys in Redis. The SessoionId has been saved. You can flushdb to clear the redis data. The SessoionId will change
The above introduces the implementation of Session sharing by Redis+Nginx+Tomcat, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.