Class RedisSessionRepository
java.lang.Object
org.springframework.session.data.redis.RedisSessionRepository
- All Implemented Interfaces:
SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
public class RedisSessionRepository
extends Object
implements SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
A
SessionRepository implementation that uses Spring Data's
RedisOperations to store sessions is Redis.
This implementation does not support publishing of session events.
- Since:
- 2.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default namespace for each key and channel in Redis used by Spring Session. -
Constructor Summary
ConstructorsConstructorDescriptionRedisSessionRepository(org.springframework.data.redis.core.RedisOperations<String, Object> sessionRedisOperations) Create a newRedisSessionRepositoryinstance. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.session.data.redis.RedisSessionRepository.RedisSessionCreates a newSessionthat is capable of being persisted by thisSessionRepository.voiddeleteById(String sessionId) org.springframework.session.data.redis.RedisSessionRepository.RedisSessionReturns theRedisOperationsused for sessions.voidsave(org.springframework.session.data.redis.RedisSessionRepository.RedisSession session) Ensures theSessioncreated bySessionRepository.createSession()is saved.voidsetDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated.voidsetFlushMode(FlushMode flushMode) Set the flush mode.voidsetRedisKeyNamespace(String namespace) Set the Redis key namespace.voidsetSaveMode(SaveMode saveMode) Set the save mode.
-
Field Details
-
DEFAULT_KEY_NAMESPACE
The default namespace for each key and channel in Redis used by Spring Session.- See Also:
-
-
Constructor Details
-
RedisSessionRepository
public RedisSessionRepository(org.springframework.data.redis.core.RedisOperations<String, Object> sessionRedisOperations) Create a newRedisSessionRepositoryinstance.- Parameters:
sessionRedisOperations- theRedisOperationsto use for managing sessions
-
-
Method Details
-
setDefaultMaxInactiveInterval
Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 30 minutes.- Parameters:
defaultMaxInactiveInterval- the default maxInactiveInterval
-
setRedisKeyNamespace
Set the Redis key namespace.- Parameters:
namespace- the Redis key namespace
-
setFlushMode
Set the flush mode.- Parameters:
flushMode- the flush mode
-
setSaveMode
Set the save mode.- Parameters:
saveMode- the save mode
-
createSession
public org.springframework.session.data.redis.RedisSessionRepository.RedisSession createSession()Description copied from interface:SessionRepositoryCreates a newSessionthat is capable of being persisted by thisSessionRepository.This allows optimizations and customizations in how the
Sessionis persisted. For example, the implementation returned might keep track of the changes ensuring that only the delta needs to be persisted on a save.- Specified by:
createSessionin interfaceSessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>- Returns:
- a new
Sessionthat is capable of being persisted by thisSessionRepository
-
save
public void save(org.springframework.session.data.redis.RedisSessionRepository.RedisSession session) Description copied from interface:SessionRepositoryEnsures theSessioncreated bySessionRepository.createSession()is saved.Some implementations may choose to save as the
Sessionis updated by returning aSessionthat immediately persists any changes. In this case, this method may not actually do anything.- Specified by:
savein interfaceSessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>- Parameters:
session- theSessionto save
-
findById
public org.springframework.session.data.redis.RedisSessionRepository.RedisSession findById(String sessionId) Description copied from interface:SessionRepository- Specified by:
findByIdin interfaceSessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>- Parameters:
sessionId- theSession.getId()to lookup- Returns:
- the
Sessionby theSession.getId()or null if noSessionis found.
-
deleteById
Description copied from interface:SessionRepository- Specified by:
deleteByIdin interfaceSessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>- Parameters:
sessionId- theSession.getId()to delete
-
getSessionRedisOperations
public org.springframework.data.redis.core.RedisOperations<String,Object> getSessionRedisOperations()Returns theRedisOperationsused for sessions.- Returns:
- the
RedisOperationsused for sessions
-