Redis session manager is pluggable one. It uses to store sessions into Redis for easy distribution of HTTP Requests across a cluster of Tomcat servers. Sessions are implemented as as non-sticky i.e, each request is forwarded to any server in round-robin manner.
The HTTP Requests session setAttribute(name, value) method stores the session into Redis (must be Serializable) immediately and the session getAttribute(name) method request directly from Redis. Also, the inactive sessions has been removed based on the session time-out configuration.
It supports, both single redis master and redis cluster based on the redis-server.properties configuration.
Going forward, we no need to enable sticky session (JSESSIONID) in Load balancer.
Support HTTPS(SSL).
- Apache Tomcat 7
- Apache Tomcat 8 (recommended)
- Apache Tomcat 9 (recommended)
- jedis.jar(2.9.0)
- commons-pool2.jar(2.4.2)
- commons-logging.jar(1.2)
- If you want put Object into Session,it must be Serializable
-
Extract downloaded package (tomcat-redis-session-manager.zip) to configure Redis credentials in redis-server.properties file and move the file to tomcat/conf directory
- tomcat/conf/redis-server.properties
- modify configuration in [redis-server.properties]
-
Move the downloaded jars to tomcat/lib directory
- tomcat/lib/
-
Add the below two lines in tomcat/conf/context.xml
- <Valve className="com.leefine.tomcat.redis.SessionHandlerValve" />
- <Manager className="com.leefine.tomcat.redis.SessionManager" />
-
Verify the session expiration time in tomcat/conf/web.xml
- <session-config>
- <session-timeout>60</session-timeout>
- </session-config>
-
Config Nginx
- Modify conf/Nginx.conf In Nginx
- this is a configiration demo: https://github.com/leefine/TomcatRedisSessionManager/blob/master/conf/nginx.conf
- This supports, both redis stand-alone and multiple node cluster based on the redis-server.properties configuration.
- Before 1.0.3 ,That does't support HttpSessionListener(if you want to use [sessionDestroyed])
- From 1.0.3 ,That support HttpSessionListener(if you want to use [sessionDestroyed])
- No need to modify web application,if use spring-session you need spring framework
- Just modify tomcat conf and add jars
- Only work with tomcat,Spring-session can work with tomcat,jetty,jboss,etc