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 Details

    • DEFAULT_KEY_NAMESPACE

      public static final String 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 new RedisSessionRepository instance.
      Parameters:
      sessionRedisOperations - the RedisOperations to use for managing sessions
  • Method Details

    • setDefaultMaxInactiveInterval

      public void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval)
      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

      public void setRedisKeyNamespace(String namespace)
      Set the Redis key namespace.
      Parameters:
      namespace - the Redis key namespace
    • setFlushMode

      public void setFlushMode(FlushMode flushMode)
      Set the flush mode.
      Parameters:
      flushMode - the flush mode
    • setSaveMode

      public void setSaveMode(SaveMode saveMode)
      Set the save mode.
      Parameters:
      saveMode - the save mode
    • createSession

      public org.springframework.session.data.redis.RedisSessionRepository.RedisSession createSession()
      Description copied from interface: SessionRepository
      Creates a new Session that is capable of being persisted by this SessionRepository.

      This allows optimizations and customizations in how the Session is 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:
      createSession in interface SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
      Returns:
      a new Session that is capable of being persisted by this SessionRepository
    • save

      public void save(org.springframework.session.data.redis.RedisSessionRepository.RedisSession session)
      Description copied from interface: SessionRepository
      Ensures the Session created by SessionRepository.createSession() is saved.

      Some implementations may choose to save as the Session is updated by returning a Session that immediately persists any changes. In this case, this method may not actually do anything.

      Specified by:
      save in interface SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
      Parameters:
      session - the Session to save
    • findById

      public org.springframework.session.data.redis.RedisSessionRepository.RedisSession findById(String sessionId)
      Description copied from interface: SessionRepository
      Gets the Session by the Session.getId() or null if no Session is found.
      Specified by:
      findById in interface SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
      Parameters:
      sessionId - the Session.getId() to lookup
      Returns:
      the Session by the Session.getId() or null if no Session is found.
    • deleteById

      public void deleteById(String sessionId)
      Description copied from interface: SessionRepository
      Deletes the Session with the given Session.getId() or does nothing if the Session is not found.
      Specified by:
      deleteById in interface SessionRepository<org.springframework.session.data.redis.RedisSessionRepository.RedisSession>
      Parameters:
      sessionId - the Session.getId() to delete
    • getSessionRedisOperations

      public org.springframework.data.redis.core.RedisOperations<String,Object> getSessionRedisOperations()
      Returns the RedisOperations used for sessions.
      Returns:
      the RedisOperations used for sessions
    • setSessionIdGenerator

      public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
      Set the SessionIdGenerator to use to generate session ids.
      Parameters:
      sessionIdGenerator - the SessionIdGenerator to use
      Since:
      3.2
    • setRedisSessionMapper

      public void setRedisSessionMapper(BiFunction<String,Map<String,Object>,MapSession> redisSessionMapper)
      Set the BiFunction used to map MapSession to a ReactiveRedisSessionRepository.RedisSession.
      Parameters:
      redisSessionMapper - the mapper to use, cannot be null
      Since:
      3.2