資源下載
實作
<code><span>Engine</span><span>name</span>=<span>"Catalina"</span><span>defaultHost</span>=<span>"localhost"</span>>?</code>
若加上jvmRoute,會導致redis內容佔用過大,jvmRoute會被循環複製進redis中,導致記憶體爆滿。如下圖:
<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>
上述方式是整個Tomcat都採用redis儲存Session,我們也可以使用在confCatalinalocalhost下加入一個xmlcat都採用redis單獨對此專案採用redis,如加入一個ROOT.xml,程式碼如下:
<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>
測試
測試方式請參考《Tomcat群集與Session負載》
同時查看Redis中的keys,已將SessoionId保存,可以flushdb清空redis數據,SessoionId將改變
以上就介紹了Redis+Nginx+Tomcat實現Session共享,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。