Springboot session共用(使用redis)

來源:互聯網
上載者:User

標籤:redis管理   div   pre   min   時間   pool   叢集   str   col   

前提:需要使用redis做session儲存


1.引入spring-session-data-redis包

    <!-- Redis -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-redis</artifactId>
    </dependency>

    <!-- Spring-Session -->
    <dependency>
      <groupId>org.springframework.session</groupId>
      <artifactId>spring-session-data-redis</artifactId>
    </dependency>

    註:該包的作用,是指將session交給redis管理

 

[email protected]/@EnableSpringHttpSession

  啟動類需要添加註解@EnableRedisHttpSession,標識啟用redis儲存httpsession

 

3.配置redis

# Redis 叢集
spring.redis.cluster.nodes=192.168.3.208:7001,192.168.3.208:7002,192.168.3.208:7003,192.168.3.208:7004,192.168.3.208:7005,192.168.3.208:7006

# 單個redis 與上面的叢集二選一

spring.redis.host=localhost

## 串連池最大串連數(使用負值表示沒有限制)
spring.redis.pool.max-active=300
## Redis資料庫索引(預設為0)
spring.redis.database=0
## 串連池最大阻塞等待時間(使用負值表示沒有限制)
spring.redis.pool.max-wait=-1
## 串連池中的最大空閑串連
spring.redis.pool.max-idle=100
## 串連池中的最小空閑串連
spring.redis.pool.min-idle=20
## 連線逾時時間(毫秒)
spring.redis.timeout=60000

 

以上配置過REDIS與SESSION後,在使用分布式多伺服器應用後,每個服務的HTTPSESSION的資訊都共用在相同的redis緩衝裡。

 

Springboot session共用(使用redis)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.