Polish "Add support for configuring Spring Session SaveMode"
See gh-17514
This commit is contained in:
@@ -75,8 +75,8 @@ class RedisSessionConfiguration {
|
||||
}
|
||||
setRedisNamespace(redisSessionProperties.getNamespace());
|
||||
setFlushMode(redisSessionProperties.getFlushMode());
|
||||
setCleanupCron(redisSessionProperties.getCleanupCron());
|
||||
setSaveMode(redisSessionProperties.getSaveMode());
|
||||
setCleanupCron(redisSessionProperties.getCleanupCron());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@ public class RedisSessionProperties {
|
||||
*/
|
||||
private FlushMode flushMode = FlushMode.ON_SAVE;
|
||||
|
||||
/**
|
||||
* Sessions save mode. Determines how session changes are tracked and saved to the
|
||||
* session store.
|
||||
*/
|
||||
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* The configure action to apply when no user defined ConfigureRedisAction bean is
|
||||
* present.
|
||||
@@ -52,12 +58,6 @@ public class RedisSessionProperties {
|
||||
*/
|
||||
private String cleanupCron = DEFAULT_CLEANUP_CRON;
|
||||
|
||||
/**
|
||||
* Sessions save mode. Determines how session changes are tracked and saved to the
|
||||
* session store.
|
||||
*/
|
||||
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;
|
||||
|
||||
public String getNamespace() {
|
||||
return this.namespace;
|
||||
}
|
||||
@@ -74,6 +74,14 @@ public class RedisSessionProperties {
|
||||
this.flushMode = flushMode;
|
||||
}
|
||||
|
||||
public SaveMode getSaveMode() {
|
||||
return this.saveMode;
|
||||
}
|
||||
|
||||
public void setSaveMode(SaveMode saveMode) {
|
||||
this.saveMode = saveMode;
|
||||
}
|
||||
|
||||
public String getCleanupCron() {
|
||||
return this.cleanupCron;
|
||||
}
|
||||
@@ -90,14 +98,6 @@ public class RedisSessionProperties {
|
||||
this.configureAction = configureAction;
|
||||
}
|
||||
|
||||
public SaveMode getSaveMode() {
|
||||
return this.saveMode;
|
||||
}
|
||||
|
||||
public void setSaveMode(SaveMode saveMode) {
|
||||
this.saveMode = saveMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategies for configuring and validating Redis.
|
||||
*/
|
||||
|
||||
@@ -65,8 +65,8 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||
.withPropertyValues("spring.session.store-type=redis",
|
||||
"spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE, "0 * * * * *",
|
||||
SaveMode.ON_SET_ATTRIBUTE));
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
|
||||
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,19 +76,19 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||
JdbcOperationsSessionRepository.class, MongoOperationsSessionRepository.class))
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withPropertyValues("spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE, "0 * * * * *",
|
||||
SaveMode.ON_SET_ATTRIBUTE));
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
|
||||
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void redisSessionStoreWithCustomizations() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withPropertyValues("spring.session.store-type=redis", "spring.session.redis.namespace=foo",
|
||||
"spring.session.redis.flush-mode=immediate", "spring.session.redis.cleanup-cron=0 0 12 * * *",
|
||||
"spring.session.redis.save-mode=on-get-attribute",
|
||||
"spring.session.redis.flush-mode=immediate", "spring.session.redis.save-mode=on-get-attribute",
|
||||
"spring.session.redis.cleanup-cron=0 0 12 * * *",
|
||||
"spring.redis.port=" + redis.getFirstMappedPort())
|
||||
.run(validateSpringSessionUsesRedis("foo:event:0:created:", FlushMode.IMMEDIATE, "0 0 12 * * *",
|
||||
SaveMode.ON_GET_ATTRIBUTE));
|
||||
.run(validateSpringSessionUsesRedis("foo:event:0:created:", FlushMode.IMMEDIATE,
|
||||
SaveMode.ON_GET_ATTRIBUTE, "0 0 12 * * *"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,7 +119,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesRedis(
|
||||
String sessionCreatedChannelPrefix, FlushMode flushMode, String cleanupCron, SaveMode saveMode) {
|
||||
String sessionCreatedChannelPrefix, FlushMode flushMode, SaveMode saveMode, String cleanupCron) {
|
||||
return (context) -> {
|
||||
RedisOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
RedisOperationsSessionRepository.class);
|
||||
|
||||
Reference in New Issue
Block a user