Skip to content

leefine/TomcatRedisSessionManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

105 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tomcat Redis Session Manager

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).

Supports:

  • Apache Tomcat 7
  • Apache Tomcat 8 (recommended)
  • Apache Tomcat 9 (recommended)

Dependency:

  1. jedis.jar(2.9.0)
  2. commons-pool2.jar(2.4.2)
  3. commons-logging.jar(1.2)
  4. If you want put Object into Session,it must be Serializable

Steps to be done,

  1. 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]
  2. Move the downloaded jars to tomcat/lib directory

    • tomcat/lib/
  3. Add the below two lines in tomcat/conf/context.xml

    • <Valve className="com.leefine.tomcat.redis.SessionHandlerValve" />
    • <Manager className="com.leefine.tomcat.redis.SessionManager" />
  4. Verify the session expiration time in tomcat/conf/web.xml

    • <session-config>
    • <session-timeout>60</session-timeout>
    • </session-config>
  5. Config Nginx

Note:

  • 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])

Compare with Spring-Session:

  • 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

About

Tomcat Redis Session Manager For Load Banlance

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages