skip to Main Content

I am new to spring-data-redis. I have integrated it with a spring-boot application. As part of this, I have added a few configs as follows:

spring.session.store-type=redis
spring.session.redis.namespace=tc
server.servlet.session.timeout=-1
server.servlet.session.cookie.name=UISESSION
server.servlet.session.cookie.http-only=true

I don’t want the user sessions to persist forever in REDIS. As per How to set Redis Http Session Timout to Unlimited in Spring, even after having the expiry timeout -1, I see all records are getting expired.

That’s why I see different UISESSION cookie values in request headers every day. I want a permanent value of UISESSION for my Spring boot application for a given end user.

I am not getting any idea regarding how to achieve this. Could anyone please help here? Thanks.

2

Answers


  1. With spring boot 3, property name is "spring.cache.redis.time-to-live", please cross check your property name set.

    Login or Signup to reply.
  2. You can adjust the Redis session configuration to set a longer TTL (Time-To-Live) for session keys. This ensures that user sessions remain active for a longer duration without expiring. Here’s how you can achieve this:

    Configure Redis Session TTL:
    In your Spring Boot application, you need to configure the Redis session properties to set a longer TTL for session keys. You can do this in your application.properties or application.yml file.
    For example, to set the session timeout to 1 hour (3600 seconds), you can add the following

    spring:
      session:
        store-type: redis
        redis:
          namespace: your-application-name
          flush-mode: on-save
          ttl: 3600 # TTL in seconds (1 hour)
    

    Disable Session Expiration:

    If you want to completely disable session expiration, you can set the TTL to a very large value or to -1 to indicate that sessions should never expire. However, be cautious with this approach, as it can lead to memory consumption issues if sessions are never cleaned up.

    spring:
      session:
        store-type: redis
        redis:
          namespace: your-application-name
          flush-mode: on-save
          ttl: -1 # Disable session expiration
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search