SpringBoot-整合redis实现分布式session共享
所需依赖
<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>
所需配置
- yml配置
spring:
application:
name: consumer-demo
redis:
# redis数据库索引(默认为0)
database: 0
# redis服务器地址(默认为localhost)
host: xxx.xxx.xxx.xxx
# redis端口(默认为6379)
port: 6379
# redis访问密码(默认为空)
password: xxxx
# redis连接超时时间(单位为毫秒)
timeout: 3000
# redis连接池配置
jedis:
pool:
# 最大可用连接数(默认为8,负数表示无限)
max-active: 8
# 最大空闲连接数(默认为8,负数表示无限)
max-idle: 8
# 最小空闲连接数(默认为0,该值只有为正数才有作用)
min-idle: 0
# 从连接池中获取连接最大等待时间(默认为-1,单位为毫秒,负数表示无限)
max-wait: -1
- 需要开启
@EnableRedisHttpSession
然后就可以使用了,您只需获取Session即可。
SpringBoot-整合redis实现分布式session共享
https://blog.cikaros.top/doc/8c5f6480.html