Giter VIP home page Giter VIP logo

redis-session-manager's Introduction

Redis Session Manager for Tomcat 8

Tomcat 8 / Java 8 session manager to store sessions in Redis.

Goals

  • Ability to use different Java Redis clients (defaults to a Redisson) with client-specific serializers (default to standard java serialization)
  • Session save configuration to allow persistence [after a request|when an attribute changes]
  • Ignore certain requests (e.g. for static resources)

Usage

  • Copy redis-session-manager-with-dependencies-VERSION.jar to tomcat/lib
  • Default configuration: (communicates with redis on localhost:6379)
<Manager className="com.crimsonhexagon.rsm.redisson.SingleServerSessionManager" />
  • Full configuration (showing default values):
<Manager className="com.crimsonhexagon.rsm.redisson.SingleServerSessionManager"
	endpoint="localhost:6379"
	sessionKeyPrefix="_rsm_"
	saveOnChange="false"
	forceSaveAfterRequest="false"
	dirtyOnMutation="false"
	ignorePattern=".*\\.(ico|png|gif|jpg|jpeg|swf|css|js)$"
	connectionPoolSize="100"
	database="0"
	password="<null>"
	timeout="60000"
	pingTimeout="1000"
	retryAttempts="20"
	retryInterval="1000"
/>
  • endpoint: hostname:port of the redis server. Must be a primary endpoint (read/write) and not a read replicate (read-only).
  • sessionKeyPrefix: prefix for redis keys. Useful for situations where 1 redis cluster serves multiple application clusters with potentially conflicting session IDs.
  • saveOnChange: if true, the session will be persisted to redis immediately when any attribute is modified. When false, a modified session is persisted to redis when the request is complete.
  • forceSaveAfterRequest: if true, the session will be persisted to redis when the request completes regardless of whether the session has detected a change to its state.
  • ignorePattern: Java Pattern String to be matched against the request URI (does not include the query string). If matched, the request will not be processed by the redis session manager.

AWS ElastiCache usage

Version 2.0.0 added additional support for ElastiCache Replication Groups. Applicable configuration:

<Manager className="com.crimsonhexagon.rsm.redisson.ElasticacheSessionManager"
	nodes="node1.cache.amazonaws.com:6379 node2.cache.amazonaws.com:6379 ..."
	nodePollInterval="1000"
	sessionKeyPrefix="_rsm_"
	saveOnChange="false"
	forceSaveAfterRequest="false"
	dirtyOnMutation="false"
	ignorePattern=".*\\.(ico|png|gif|jpg|jpeg|swf|css|js)$"
	masterConnectionPoolSize="100"
	slaveConnectionPoolSize="100"
	database="0"
	password="<null>"
	timeout="60000"
	pingTimeout="1000"
	retryAttempts="20"
	retryInterval="1000"
/>

nodes is a space-separated list of all nodes in the replication group. There is no default value; failure to specify this will result in a failure to start. nodePollInterval is the interval for polling each node in the group to determine if it is the master or a slave.

Notes on object mutation

  • TL;DR: avoid mutation of objects pulled from the session. If you must do this, read on.
  • Changes made directly to an object in the session without mutating the session will not be persisted to redis. E.g. session.getAttribute("anObject").setFoo("bar") will not result in the session being marked dirty. forceSaveAfterRequest can be used as a workaround, but this is inefficient. A dirty workaround would be to mark the session as dirty by session.removeAttribute("nonExistentKey")
  • It is possible for an object to be mutated and session.setAttribute("anObject") invoked without the session being marked as dirty due to the session object and mutated object being references to the same actual object. dirtyOnMutation will mark the session as dirty whenever setAttribute() is invoked. This is generally safe but is disabled by default to avoid unnecessary persists.

redis-session-manager's People

Contributors

azenkov avatar scubasau avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.