Class SortedSetRedisSessionExpirationStore

java.lang.Object
org.springframework.session.data.redis.SortedSetRedisSessionExpirationStore
All Implemented Interfaces:
RedisSessionExpirationStore

public class SortedSetRedisSessionExpirationStore extends Object implements RedisSessionExpirationStore
Uses a sorted set to store the expiration times for sessions. The score of each entry is the expiration time of the session (calculated via Session.getLastAccessedTime() + Session.getMaxInactiveInterval()). The value is the session id. Note that cleanupExpiredSessions() only retrieves up to 100 sessions at a time by default, use setCleanupCount(int) to increase it if needed.
Since:
3.4
  • Constructor Details

    • SortedSetRedisSessionExpirationStore

      public SortedSetRedisSessionExpirationStore(org.springframework.data.redis.core.RedisOperations<String,Object> redisOps, String namespace)
  • Method Details

    • save

      public void save(RedisIndexedSessionRepository.RedisSession session)
      Save the session id associated with the expiration time into the sorted set.
      Specified by:
      save in interface RedisSessionExpirationStore
      Parameters:
      session - the session to save
    • remove

      public void remove(String sessionId)
      Remove the session id from the sorted set.
      Specified by:
      remove in interface RedisSessionExpirationStore
      Parameters:
      sessionId - the session id
    • cleanupExpiredSessions

      public void cleanupExpiredSessions()
      Retrieves the sessions that are expected to be expired and invoke touch(String) on each of the session keys, resolved via getSessionKey(String).
      Specified by:
      cleanupExpiredSessions in interface RedisSessionExpirationStore
    • setNamespace

      public void setNamespace(String namespace)
      Set the namespace for the keys.
      Parameters:
      namespace - the namespace
    • setClock

      public void setClock(Clock clock)
      Configure the clock used when retrieving expired sessions for clean-up.
      Parameters:
      clock - the clock
    • setCleanupCount

      public void setCleanupCount(int cleanupCount)
      Configures how many sessions will be queried at a time to be cleaned up. Defaults to 100.
      Parameters:
      cleanupCount - how many sessions to be queried, must be bigger than 0.