springboot与redis的无缝整合(分布式)

参考博客 : https://blog.csdn.net/csao204282/article/details/54092997 

1 首先得引入依赖

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

2 配置

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60*60)
@Configuration
public class RedisConfig extends CachingConfigurerSupport{
    
   
    
}



核心配置文件application.yml的配置

session:
store-type: redis

#redis配置
redis:
database: 2
host: localhost
port: 6379
password:
timeout: 0
pool:
max-active: 10 #连接池最大连接数(使用负值表示没有限制)
max-wait: 1000 #连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 8 #连接池中的最大空闲连接
min-idle: 0 #连接池中的最小空闲连接

注: 这样就完成了redis分布式的配置(可以用两个项目测试,就知道是分布式的了)..至于是如何将session中的值存到redis的,就得看看源码了,,

原文地址:https://www.cnblogs.com/liyong888/p/8651568.html