- Type Parameters:
A
- the session data type
- All Implemented Interfaces:
BasicSessionStore<A>
,SessionStore<A,
Session<A>>
A basic session store implementation that stores sessions and their data in a Redis data store.
Sessions are stored in Redis hash containing the session attributes (i.e. creation time, maximum inactive interval...) and the session data. They are stored with a two minutes expiration buffer in order to make sure session data are still available to the limits.
Session data are stored as JSON strings, as a result the session data type must be defined in a way that enables an object mapper to read and write data.
This implementation uses a SessionDataSaveStrategy
to determine whether resolved session data should be saved along with the session.
- Since:
- 1.13
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The Redis basic session store builder. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default Redis key prefix.static final String
The creation time hash field name.static final String
The expiration time hash field name.static final String
The last accessed time hash field name.static final String
The maximum inactive interval time hash field name.static final String
The data hash field name.Fields inherited from class io.inverno.mod.session.AbstractSessionStore
expireAfterPeriod, maxInactiveInterval, sessionIdGenerator
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> RedisBasicSessionStore.Builder
<A> builder
(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Class<A> sessionDataType) Creates a Redis basic session store builder usingSessionIdGenerator.uuid()
session id generator.static <A> RedisBasicSessionStore.Builder
<A> builder
(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Class<A> sessionDataType, SessionIdGenerator<A, Session<A>> sessionIdGenerator) Creates a Redis basic session store builder.static <A> RedisBasicSessionStore.Builder
<A> builder
(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Type sessionDataType) Creates a Redis basic session store builder usingSessionIdGenerator.uuid()
session id generator.static <A> RedisBasicSessionStore.Builder
<A> builder
(SessionIdGenerator<A, Session<A>> sessionIdGenerator, RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Type sessionDataType) Creates a Redis basic session store builder.create()
Creates a new session in the session store.Returns the session identified by the specified session id.Returns the data of the session identified by the specified session id.Returns the session Redis key prefix.Returns the session id generator.Moves the session identified by the specified identifier to a new identifier.Removes the session identified by the specified identifier.Saves the specified session.Methods inherited from class io.inverno.mod.session.AbstractSessionStore
getExpireAfterPeriod, getMaxInactiveInterval
-
Field Details
-
DEFAULT_KEY_PREFIX
The default Redis key prefix.- See Also:
-
FIELD_CREATION_TIME
The creation time hash field name.- See Also:
-
FIELD_LAST_ACCESSED_TIME
The last accessed time hash field name.- See Also:
-
FIELD_MAX_INACTIVE_INTERVAL
The maximum inactive interval time hash field name.- See Also:
-
FIELD_EXPIRATION_TIME
The expiration time hash field name.- See Also:
-
FIELD_SESSION_DATA
The data hash field name.- See Also:
-
-
Method Details
-
builder
public static <A> RedisBasicSessionStore.Builder<A> builder(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Class<A> sessionDataType) Creates a Redis basic session store builder using
SessionIdGenerator.uuid()
session id generator.- Type Parameters:
A
- the session data type- Parameters:
redisClient
- a Redis clientmapper
- an object mappersessionDataType
- the session data type- Returns:
- a Redis basic session store builder
-
builder
public static <A> RedisBasicSessionStore.Builder<A> builder(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Class<A> sessionDataType, SessionIdGenerator<A, Session<A>> sessionIdGenerator) Creates a Redis basic session store builder.
- Type Parameters:
A
- the session data type- Parameters:
redisClient
- a Redis clientmapper
- an object mappersessionDataType
- the session data typesessionIdGenerator
- a session id generator- Returns:
- a Redis basic session store builder
-
builder
public static <A> RedisBasicSessionStore.Builder<A> builder(RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Type sessionDataType) Creates a Redis basic session store builder using
SessionIdGenerator.uuid()
session id generator.- Type Parameters:
A
- the session data type- Parameters:
redisClient
- a Redis clientmapper
- an object mappersessionDataType
- the session data type- Returns:
- a Redis basic session store builder
-
builder
public static <A> RedisBasicSessionStore.Builder<A> builder(SessionIdGenerator<A, Session<A>> sessionIdGenerator, RedisClient<String, String> redisClient, com.fasterxml.jackson.databind.ObjectMapper mapper, Type sessionDataType) Creates a Redis basic session store builder.
- Type Parameters:
A
- the session data type- Parameters:
sessionIdGenerator
- a session id generatorredisClient
- a Redis clientmapper
- an object mappersessionDataType
- the session data type- Returns:
- a Redis basic session store builder
-
getSessionIdGenerator
Description copied from class:AbstractSessionStore
Returns the session id generator.
- Overrides:
getSessionIdGenerator
in classAbstractSessionStore<A,
Session<A>> - Returns:
- the session id generator
-
getKeyPrefix
Returns the session Redis key prefix.
- Returns:
- the session key prefix
-
create
Description copied from interface:SessionStore
Creates a new session in the session store.
This shall physically create a new session in the data store.
- Specified by:
create
in interfaceSessionStore<A,
Session<A>> - Returns:
- a mono for creating a session
-
get
Description copied from interface:SessionStore
Returns the session identified by the specified session id.
- Specified by:
get
in interfaceSessionStore<A,
Session<A>> - Parameters:
sessionId
- a session id- Returns:
- a mono emitting the session or an empty mono if no session exists with the specified identifier
-
getData
Description copied from interface:SessionStore
Returns the data of the session identified by the specified session id.
- Specified by:
getData
in interfaceSessionStore<A,
Session<A>> - Parameters:
sessionId
- a session id- Returns:
- a mono emitting the session data or an empty mono if no session exists with specified identifier or if a session exists which does not define any data
-
move
Description copied from interface:SessionStore
Moves the session identified by the specified identifier to a new identifier.
- Specified by:
move
in interfaceSessionStore<A,
Session<A>> - Parameters:
sessionId
- a session idnewSessionId
- a new session id- Returns:
- a mono for moving a session
- Throws:
IllegalStateException
- if there is no session with the specified identifier or if a session already exists at the specified new identifier
-
remove
Description copied from interface:SessionStore
Removes the session identified by the specified identifier.
- Specified by:
remove
in interfaceSessionStore<A,
Session<A>> - Parameters:
sessionId
- a session id- Returns:
- a mono for removing a session
-
save
Description copied from interface:SessionStore
Saves the specified session.
Whether resolved session data are saved along with the session is implementation specific. Implementors must however at least guarantee that data that is explicitly set on a session using
Session.setData(Object)
are saved.- Specified by:
save
in interfaceSessionStore<A,
Session<A>> - Parameters:
session
- a session- Returns:
- a mono for saving a session
- Throws:
IllegalArgumentException
- if the specified session does not originate from this session storeIllegalStateException
- if the specified session does not exist in the store or if it was invalidated
-