Skip to content

Commit 8582b97

Browse files
committed
Use simple Redis repository by default
Closes gh-1711
1 parent 14ecf21 commit 8582b97

15 files changed

+943
-332
lines changed

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -691,7 +691,7 @@ private String getChangedSecurityName() {
691691
}
692692

693693
@Configuration
694-
@EnableRedisHttpSession(redisNamespace = "RedisIndexedSessionRepositoryITests")
694+
@EnableRedisHttpSession(redisNamespace = "RedisIndexedSessionRepositoryITests", enableIndexingAndEvents = true)
695695
static class Config extends BaseConfig {
696696

697697
@Bean

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,13 +26,10 @@
2626
import org.junit.jupiter.api.extension.ExtendWith;
2727

2828
import org.springframework.beans.factory.annotation.Autowired;
29-
import org.springframework.context.annotation.Bean;
3029
import org.springframework.context.annotation.Configuration;
31-
import org.springframework.data.redis.connection.RedisConnectionFactory;
32-
import org.springframework.data.redis.core.RedisTemplate;
3330
import org.springframework.session.MapSession;
34-
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
3531
import org.springframework.session.data.redis.RedisSessionRepository.RedisSession;
32+
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
3633
import org.springframework.test.context.ContextConfiguration;
3734
import org.springframework.test.context.junit.jupiter.SpringExtension;
3835
import org.springframework.test.context.web.WebAppConfiguration;
@@ -223,17 +220,9 @@ private static void updateSession(RedisSession session, Instant lastAccessedTime
223220
}
224221

225222
@Configuration
226-
@EnableSpringHttpSession
223+
@EnableRedisHttpSession
227224
static class Config extends BaseConfig {
228225

229-
@Bean
230-
RedisSessionRepository sessionRepository(RedisConnectionFactory redisConnectionFactory) {
231-
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
232-
redisTemplate.setConnectionFactory(redisConnectionFactory);
233-
redisTemplate.afterPropertiesSet();
234-
return new RedisSessionRepository(redisTemplate);
235-
}
236-
237226
}
238227

239228
}

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSessionExpireSessionDestroyedTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -113,7 +113,7 @@ void setLock(Object lock) {
113113
}
114114

115115
@Configuration
116-
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1)
116+
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1, enableIndexingAndEvents = true)
117117
static class Config extends BaseConfig {
118118

119119
@Bean

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ boolean taskDispatched() throws InterruptedException {
101101
}
102102

103103
@Configuration
104-
@EnableRedisHttpSession(redisNamespace = "RedisListenerContainerTaskExecutorITests")
104+
@EnableRedisHttpSession(redisNamespace = "RedisListenerContainerTaskExecutorITests", enableIndexingAndEvents = true)
105105
static class Config extends BaseConfig {
106106

107107
@Bean

spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
3434
import org.springframework.session.data.redis.RedisFlushMode;
3535
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
36+
import org.springframework.session.data.redis.RedisSessionRepository;
3637
import org.springframework.session.web.http.SessionRepositoryFilter;
3738

3839
/**
@@ -54,7 +55,8 @@
5455
* }
5556
* </pre>
5657
*
57-
* More advanced configurations can extend {@link RedisHttpSessionConfiguration} instead.
58+
* More advanced configurations can extend {@link RedisHttpSessionConfiguration} or
59+
* {@link RedisIndexedHttpSessionConfiguration} instead.
5860
*
5961
* @author Rob Winch
6062
* @author Vedran Pavic
@@ -64,7 +66,7 @@
6466
@Retention(RetentionPolicy.RUNTIME)
6567
@Target(ElementType.TYPE)
6668
@Documented
67-
@Import(RedisHttpSessionConfiguration.class)
69+
@Import(RedisHttpSessionConfigurationSelector.class)
6870
@Configuration(proxyBeanMethods = false)
6971
public @interface EnableRedisHttpSession {
7072

@@ -113,13 +115,6 @@
113115
*/
114116
FlushMode flushMode() default FlushMode.ON_SAVE;
115117

116-
/**
117-
* The cron expression for expired session cleanup job. By default runs every minute.
118-
* @return the session cleanup cron expression
119-
* @since 2.0.0
120-
*/
121-
String cleanupCron() default RedisHttpSessionConfiguration.DEFAULT_CLEANUP_CRON;
122-
123118
/**
124119
* Save mode for the session. The default is {@link SaveMode#ON_SET_ATTRIBUTE}, which
125120
* only saves changes made to session.
@@ -128,4 +123,13 @@
128123
*/
129124
SaveMode saveMode() default SaveMode.ON_SET_ATTRIBUTE;
130125

126+
/**
127+
* Indicate whether the {@link SessionRepository} should publish session events and
128+
* support fetching sessions by index. If true, a
129+
* {@link RedisIndexedSessionRepository} will be used in place of
130+
* {@link RedisSessionRepository}. This will result in slower performance.
131+
* @return true if indexing and events should be enabled, false otherwise
132+
*/
133+
boolean enableIndexingAndEvents() default false;
134+
131135
}

0 commit comments

Comments
 (0)