有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用spring在redis中存储会话的java方法

我很难用Spring将会话存储在redis中,有很多方法和概念来处理这个问题。以下列出了一些方法:

  1. Spring数据Redis
  2. 春季会议
  3. Spring会话管理器

现在的问题是,使用spring在redis中存储(删除等)会话的最佳组合是什么

如果有人能给我一个简单的解释,我将不胜感激


共 (2) 个答案

  1. # 1 楼答案

    如果您使用的是spring boot,那么应用程序所需的更改非常简单

    添加以下依赖项,并在应用程序中添加redis连接配置。酒店和你很好

            <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>
    

    我在https://springhow.com/spring-boot-security/session-redis/上有一篇关于这个的详细帖子

  2. # 2 楼答案

    你有点困惑:

    • 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.

    使用Spring框架就是使用Spring会话。您只需将其配置为使用Redis作为后端,如official documentation samplesample project中的spring应用程序中的Redis会话