Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for auto-configuring an indexed reactive session repository #42604

Closed
TMRGZ opened this issue Oct 12, 2024 · 3 comments
Closed

Add support for auto-configuring an indexed reactive session repository #42604

TMRGZ opened this issue Oct 12, 2024 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@TMRGZ
Copy link

TMRGZ commented Oct 12, 2024

As noted in the Spring Session configuration documentation, reactive indexed repositories can only be enabled through annotations, which limits the configuration flexibility via application.properties.

Additionally, the auto-configuration classes do not account for important properties such as configureRedisAction and namespace.

Simply adding the equivalent methods resolves this issue, as shown in the following configuration:

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "spring.session.redis", name = "repository-type", havingValue = "indexed")
@Import(RedisIndexedWebSessionConfiguration.class)
@EnableConfigurationProperties(RedisSessionProperties.class)
static class IndexedRedisSessionConfiguration {

  @Bean
  @ConditionalOnMissingBean
  ConfigureReactiveRedisAction configureRedisAction(RedisSessionProperties redisSessionProperties) {
    return switch (redisSessionProperties.getConfigureAction()) {
      case NOTIFY_KEYSPACE_EVENTS -> new ConfigureNotifyKeyspaceEventsReactiveAction();
      case NONE -> ConfigureReactiveRedisAction.NO_OP;
    };
  }

  @Bean
  @Order(Ordered.HIGHEST_PRECEDENCE)
  ReactiveSessionRepositoryCustomizer<ReactiveRedisIndexedSessionRepository> springBootSessionRepositoryCustomizer(
      SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties,
      ServerProperties serverProperties) {
    return (sessionRepository) -> {
      PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
      map.from(sessionProperties.determineTimeout(() -> serverProperties.getReactive().getSession().getTimeout()))
          .to(sessionRepository::setDefaultMaxInactiveInterval);
      map.from(redisSessionProperties::getNamespace).to(sessionRepository::setRedisKeyNamespace);
      map.from(redisSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
    };
  }

}

Additionally, it would be helpful to add a similar check for non-indexed repositories when the cleanup-cron property is enabled.

I can provide a PR if needed

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 12, 2024
@wilkinsona
Copy link
Member

Thanks for the report.

The missing support for spring.session.redis.configure-action looks like an oversight. Support was added to Spring Session in 3.3 to which we upgraded in Spring Boot 3.3. We'll have to discuss this as a team to see if we want to treat adding support as enhancement or as a bug of omission.

As far as I can tell, spring.session.redis.namespace is already supported when using a reactive session repository:

This functionality was added when we started supporting reactive in Spring Boot 2.0.

Can you please clarify what you believe to be missing from the reactive session support beyond spring.session.redis.configure-action?

@wilkinsona wilkinsona added for: team-attention An issue we'd like other members of the team to review status: waiting-for-feedback We need additional information before we can continue labels Oct 14, 2024
@TMRGZ
Copy link
Author

TMRGZ commented Oct 14, 2024

That config works when the default reactive redis session repository is used, but since to use the indexed one you have to use the @EnableRedisIndexedWebSession annotation it's ignored and uses the configurations provided in the annotation.

I'll clarify that this affects only the reactive indexed repository

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 14, 2024
@philwebb philwebb added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 16, 2024
@philwebb philwebb added this to the 3.x milestone Oct 16, 2024
@wilkinsona wilkinsona changed the title Feature parity between Reactive and Non reactive Spring Session Redis autoconfigurators Feature parity between reactive and non-reactive Spring Session Redis auto-configuration Oct 22, 2024
@wilkinsona wilkinsona changed the title Feature parity between reactive and non-reactive Spring Session Redis auto-configuration Add support for auto-configuring an indexed reactive session repository Oct 22, 2024
@wilkinsona wilkinsona self-assigned this Oct 22, 2024
@wilkinsona wilkinsona modified the milestones: 3.x, 3.4.x, 3.4.0-RC1 Oct 22, 2024
@wilkinsona
Copy link
Member

I've opened #42834 to look at improving the properties so that it's clearer which properties apply in which situations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants