Each session is stored in Redis as a Hash. Each session is set and updated using the HMSET command. An example of how each session is stored can be seen below.
HMSET spring:session:sessions:creationTime 1404360000000 maxInactiveInterval 1800 lastAccessedTime 1404360000000 sessionAttr: someAttrValue sessionAttr2: someAttrValue2
An expiration is associated to each session using the EXPIRE command based upon the {@link org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession#getMaxInactiveInterval()}. For example:
EXPIRE spring:session:sessions:1800
The {@link RedisSession} keeps track of the properties that have changed andonly updates those. This means if an attribute is written once and read many times we only need to write that attribute once. For example, assume the session attribute "sessionAttr2" from earlier was updated. The following would be executed upon saving:
HMSET spring:session:sessions:Each session expiration is also tracked to the nearest minute. This allows a background task to cleanup expired sessions in a deterministic fashion. For example:sessionAttr2: newValue EXPIRE spring:session:sessions: 1800
SADD spring:session:expirations:The Redis expiration is still placed on each key to ensure that if the server is down when the session expires, it is still cleaned up. @since 1.0 @author Rob WinchEXPIRE spring:session:expirations: 1800
|
|