博客详情

springboot中集成redis-session实现session共享 (原创)

作者: 朝如青丝暮成雪
发布时间:2021-02-19 11:22:53  文章分类:java编程   阅读(839)  评论(0)

1.pom.xml中引入

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


2、RedisSessionConfig 配置,配置redisSession有效期


import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Configuration
//maxInactiveIntervalInSeconds 默认是1800秒过期
@EnableRedisHttpSession(maxInactiveIntervalInSeconds=1800)
public class RedisSessionConfig {


}


3、bootstrap.yml配置,配置redis连接池


spring:
  redis:
    host: 192.168.11.41
    port: 6379
    password: 123456
    ssl: false
    database: 10
    timeout: 30s
    #基于netty nio
    lettuce:
      pool:
        max-active: 8 #缺省值8
        max-idle: 4 #缺省值8
        min-idle: 0 #缺省值0
        max-wait: 30s #缺省值-1




评论信息
暂无评论
发表评论

亲,您还没有登陆,暂不能评论哦! 去 登陆 | 注册

博主信息
   
数据加载中,请稍候...
文章分类
   
数据加载中,请稍候...
阅读排行
 
数据加载中,请稍候...
评论排行
 
数据加载中,请稍候...

Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1

鄂公网安备 42011102000739号