Search code examples
springsessionredistimeoutspring-session

Spring Session with Redis - server.session.timeout has no effect


I follow this documentation to set up sessions in my Spring Boot application: https://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-redis.html

application.properties

spring.session.store-type=redis
server.session.timeout=10

After sending in a request, I see the following records in redis:

127.0.0.1:6379> keys *
1) "spring:session:sessions:4b524c1e-e133-4d04-8b5b-40ffc3685af3"
2) "spring:session:sessions:expires:c1e2792f-f001-4a02-b812-39ab68f719ea"
3) "spring:session:sessions:expires:4b524c1e-e133-4d04-8b5b-40ffc3685af3"
4) "spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:105121963489487663346"
5) "spring:session:expirations:1521492480000"

I expect these records to disappear after 10 seconds (because of the server.session.timeout property), but the data stays even after several minutes.

How to set up session time out in Spring Sessions properly?


Solution

  • You are using a deprecated server.session.timeout which was replaced with server.servlet.session.timeout in Spring Boot 2.0. With the change from PR I've opened against your sample repo the desired session timeout is applied correctly.

    Please take time to get familiar with Spring Boot 2.0 Migration Guide and consider using spring-boot-properties-migrator module.