Annotation Interface EnableRedisIndexedHttpSession
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import(RedisIndexedHttpSessionConfiguration.class)
public @interface EnableRedisIndexedHttpSession
Add this annotation to an
@Configuration class to expose the
SessionRepositoryFilter as a bean named springSessionRepositoryFilter
and backed by RedisIndexedSessionRepository. In order to leverage the
annotation, a single RedisConnectionFactory must be provided. For example:
@Configuration(proxyBeanMethods = false)
@EnableRedisIndexedHttpSession
public class RedisHttpSessionConfig {
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory();
}
}
More advanced configurations can extend RedisIndexedHttpSessionConfiguration
instead.- Since:
- 3.0.0
- See Also:
-
EnableSpringHttpSession
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe cron expression for expired session cleanup job.org.springframework.session.FlushModeFlush mode for the Redis sessions.intThe session timeout in seconds.Defines a unique namespace for keys.org.springframework.session.SaveModeSave mode for the session.
-
Element Details
-
maxInactiveIntervalInSeconds
int maxInactiveIntervalInSecondsThe session timeout in seconds. By default, it is set to 1800 seconds (30 minutes). This should be a non-negative integer.- Returns:
- the seconds a session can be inactive before expiring
- Default:
- 1800
-
redisNamespace
String redisNamespaceDefines a unique namespace for keys. The value is used to isolate sessions by changing the prefix from defaultspring:session:to<redisNamespace>:.For example, if you had an application named "Application A" that needed to keep the sessions isolated from "Application B" you could set two different values for the applications and they could function within the same Redis instance.
- Returns:
- the unique namespace for keys
- Default:
- "spring:session"
-
flushMode
org.springframework.session.FlushMode flushModeFlush mode for the Redis sessions. The default isON_SAVEwhich only updates the backing Redis whenSessionRepository.save(Session)is invoked. In a web environment this happens just before the HTTP response is committed.Setting the value to
IMMEDIATEwill ensure that the any updates to the Session are immediately written to the Redis instance.- Returns:
- the
FlushModeto use
- Default:
- ON_SAVE
-
saveMode
org.springframework.session.SaveMode saveModeSave mode for the session. The default isSaveMode.ON_SET_ATTRIBUTE, which only saves changes made to session.- Returns:
- the save mode
- Default:
- ON_SET_ATTRIBUTE
-
cleanupCron
String cleanupCronThe cron expression for expired session cleanup job. By default runs every minute.- Returns:
- the session cleanup cron expression
- Default:
- "0 * * * * *"
-