Annotation Interface EnableRedisHttpSession
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import(org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfigurationSelector.class)
@Configuration(proxyBeanMethods=false)
public @interface EnableRedisHttpSession
Add this annotation to an
@Configuration
class to expose the
SessionRepositoryFilter
as a bean named springSessionRepositoryFilter
and backed by Redis. In order to leverage the annotation, a single
RedisConnectionFactory
must be provided. For example:
@Configuration @EnableRedisHttpSession public class RedisHttpSessionConfig { @Bean public LettuceConnectionFactory redisConnectionFactory() { return new LettuceConnectionFactory(); } }More advanced configurations can extend
RedisHttpSessionConfiguration
or
RedisIndexedHttpSessionConfiguration
instead.- Since:
- 1.0
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionboolean
Indicate whether theSessionRepository
should publish session events and support fetching sessions by index.Flush mode for the Redis sessions.int
The session timeout in seconds.Deprecated.Defines a unique namespace for keys.Save 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"
-
redisFlushMode
Deprecated.since 2.2.0 in favor offlushMode()
Flush mode for the Redis sessions. The default isON_SAVE
which 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
IMMEDIATE
will ensure that the any updates to the Session are immediately written to the Redis instance.- Returns:
- the
RedisFlushMode
to use - Since:
- 1.1
- Default:
- ON_SAVE
-
flushMode
FlushMode flushModeFlush mode for the Redis sessions. The default isON_SAVE
which 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
IMMEDIATE
will ensure that the any updates to the Session are immediately written to the Redis instance.- Returns:
- the
FlushMode
to use - Since:
- 2.2.0
- Default:
- ON_SAVE
-
saveMode
SaveMode saveModeSave mode for the session. The default isSaveMode.ON_SET_ATTRIBUTE
, which only saves changes made to session.- Returns:
- the save mode
- Since:
- 2.2.0
- Default:
- ON_SET_ATTRIBUTE
-
enableIndexingAndEvents
boolean enableIndexingAndEventsIndicate whether theSessionRepository
should publish session events and support fetching sessions by index. If true, aRedisIndexedSessionRepository
will be used in place ofRedisSessionRepository
. This will result in slower performance.- Returns:
- true if indexing and events should be enabled, false otherwise
- Default:
- false
-
flushMode()