Skip to content

Add support for configuring Spring Session Redis repository #32205

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

Closed
wants to merge 1 commit into from

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Aug 31, 2022

With Spring Session moving to RedisSessionRepository as the preferred session repository, Spring Boot auto-configuration should make it possible to easily switch back to the previous default (RedisIndexedSessionRepository).

This commit introduces spring.session.redis.repository configuration property that allow selecting the desired Redis-backed session repository implementation.

Closes #30673

@@ -2757,6 +2757,20 @@
"name": "spring.session.redis.flush-mode",
"defaultValue": "on-save"
},
{
"name": "spring.session.redis.repository",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't 100% sure how to name this property, so I initially went with the simple option. Alternatively, this could maybe be named spring.session.redis.repository-type.

"description": "Redis session repository implementation to use.",
"values": [
{
"value": "default",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RedisSessionRepository by itself doesn't offer much inspiration on how to name this other than default or maybe basic.

"description": "Use default Redis session repository."
},
{
"value": "indexed",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, RedisIndexedSessionRepository makes this quite straightforward. One might get tempted to throw mention of events here as well (based on soon to be removed EnableRedisHttpSession#enableIndexingAndEvents) however I'd avoid that as support for session events is an implementation detail of a session repository (and not something expressed through a contract, like indexing capabilities).

With Spring Session moving to RedisSessionRepository as the preferred session repository, Spring Boot auto-configuration should make it possible to easily switch back to the previous default (RedisIndexedSessionRepository).

This commit introduces spring.session.redis.repository configuration property that allow selecting the desired Redis-backed session repository implementation.

Closes spring-projectsgh-30673
@wilkinsona
Copy link
Member

@vpavic I see you just force-pushed. What did you change? I was just in the process of getting this ready to merge and I don't want to miss something.

@vpavic
Copy link
Contributor Author

vpavic commented Sep 21, 2022

Hey @wilkinsona, sorry I had intended to drop a note here after force pushing but forgot to do so in the end. Nothing changed, I just rebased the branch as it was few hundred commits behind and also wanted to verify everything works as expected with the changes that were shipped with the latest Spring Session milestone yesterday.

@wilkinsona wilkinsona modified the milestones: 3.0.x, 3.0.0-M5 Sep 21, 2022
wilkinsona pushed a commit that referenced this pull request Sep 21, 2022
With Spring Session moving to RedisSessionRepository as the preferred
session repository, Spring Boot auto-configuration should make it
possible to easily switch back to the previous default
(RedisIndexedSessionRepository).

This commit introduces spring.session.redis.repository configuration
property that allows selecting the desired Redis-backed session
repository implementation.

See gh-32205
@wilkinsona
Copy link
Member

Thanks, @vpavic. I've polished things a little in 2977373, primarily to go with your repository-type idea for the property name. I've also tried to make it fail nicely if you try to configure the cleanup cron when using the default repository.

@vpavic vpavic deleted the gh-30673 branch September 21, 2022 17:33
@vpavic
Copy link
Contributor Author

vpavic commented Sep 22, 2022

I've also tried to make it fail nicely if you try to configure the cleanup cron when using the default repository.

I just tried the snapshots and this works (fails?) very nicely indeed. Very useful.

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

Successfully merging this pull request may close these issues.

Adapt to Spring Session Data Redis switching to an unindexed repository by default
4 participants