user4018604
user4018604

Reputation:

methods of storing session in redis using spring

I am in dilemma to store session in redis using Spring and there are many methods and concepts to handle this issue. Some methods are listed below:

  1. Spring Data Redis
  2. Spring Session
  3. Spring Session Manager

Now the question is what is the best combination to store (delete and so on) session in redis using spring.

I will be appreciated if someone help me with a simple explanation.

Upvotes: 3

Views: 3449

Answers (2)

Raja Anbazhagan
Raja Anbazhagan

Reputation: 4564

If you are using spring boot, then the changes you need for your application is pretty simple.

Add the following dependencies and add redis connection configuration in application.properties and you are good to go.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
        </dependency>

I have a details post about this at https://springhow.com/spring-boot-security/session-redis/

Upvotes: 0

Nick Bondarenko
Nick Bondarenko

Reputation: 6371

You're a little confused:

  • Spring Data Redis provides easy configuration and access to Redis from any type of Spring applications. It realize both low-level and high-level abstractions for interacting with the Redis store. In few words - just realization of Redis client library.
  • Spring Session provides an API and implementations for managing a user’s session information.
  • Spring Session Management is just a HTTP session related functonality focused to concurrency control, filtering and authentication strategy and do not work with Redis as is. it works with interfaces only.

Using Spring framework you are using Spring Session. You need only configure it to use Redis as backend as in official documentation sample and sample project with Redis session in spring application.

Upvotes: 3

Related Questions