3

I am looking to implementing User Session in Spring Boot application using Redis. I have came across two great dependencies that aims to achieve these goals. Spring Data Redis and Spring Session Data Redis.

However, I have tried looking for differences of these dependencies, but to no avail.

From my understanding, if I am looking at only using Redis for Session Management, then I should use Spring Session Data Redis (even though Spring Data Redis works as well, but not as elegant).

On the other hand, if I am looking at using Redis for Session Management && Caching, then Spring Data Redis is a better option.

WeiTang Lau
  • 103
  • 1
  • 11

2 Answers2

4

In general terms, Spring Session provides support for session management in Spring applications. It supports various different backends for storing session data, one of which is Redis. This Redis support is provided by Spring Session Data Redis.

Spring Session Data Redis builds on top of Spring Data Redis, using it to simplify its code that stores session data in Redis. Given this relationship between the two, this isn’t really a question of choosing one versus the other. Uses Spring Session Data Redis for session management while at the same time using Spring Data Redis to store you application’s own data is a common usage of the two projects.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Thank you for your response Andy! I see, so it is a common practice to use both Spring Data Redis and Spring Session Data Redis if necessary. However, wont this be quite a huge overhead? Especially if Spring Data Redis can perform session management as well. – WeiTang Lau Jul 01 '21 at 06:37
  • 2
    In my experience, Spring Session’s overhead is negligible. Also, Spring Data Redis cannot perform session management out of the box. You would have to write some code which would be reinventing what Spring Session already provides. – Andy Wilkinson Jul 01 '21 at 07:23
0

Yes your understanding is correct. You can find the documentation for spring session data redis here and Spring Data redis here

Justin Mathew
  • 950
  • 8
  • 34