传统项目基于tomcat cookie单体会话升级分布式会话解决方案

传统捞项目基于servlet容器 cookie单体会话改造分布式会话方案

##引入redis,spring-session依赖

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

##修改配置文件

spring:
  application:
    name: hnmop-consumer
  session:
    timeout: 3600
    store-type: redis
    redis:
      namespace: yym:session
  redis:
    lettuce:
      pool:
        max-idle: 50
        min-idle: 10
        max-wait: 300
        max-active: 25
    timeout: 30000
    cluster:
      nodes:
        - 192.168.3.156:6379
        - 192.168.3.156:6380
        - 192.168.3.156:6381
        - 192.168.3.156:6382
        - 192.168.3.156:6383
        - 192.168.3.156:6384
#        - redis-service.hdsst-ns.svc.cluster.local:6379
#        - redis-service.hdsst-ns.svc.cluster.local:6379
#        - redis-service.hdsst-ns.svc.cluster.local:6379
#        - redis-service.hdsst-ns.svc.cluster.local:6379
#        - redis-service.hdsst-ns.svc.cluster.local:6379
#        - redis-service.hdsst-ns.svc.cluster.local:6379
    password: 123456
    database: 0

##启动类加入EnableRedisHttpSession注解

@EnableRedisHttpSession(redisNamespace = "yym:session", maxInactiveIntervalInSeconds = 3600)

##原理

##spring自动配置spring.factories

##生成SessionRepositoryFilter过滤器对象

##使用包装的SessionRepositoryRequestWrapper的request   SessionRepositoryResponseWrapper的response

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值