Springboot session sharing (using Redis)

Source: Internet
Author: User
Tags redis cluster

Prerequisite: You need to use Redis for session storage


1. Introduction of Spring-session-data-redis Package

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

    Note: The purpose of this package is to refer the session to Redis management

[Email protected]/@EnableSpringHttpSession

  The startup class needs to add the annotation @enableredishttpsession, which identifies enabling Redis storage HttpSession

3. Configure Redis

# Redis Cluster
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

# single Redis with cluster two on top select one

Spring.redis.host=localhost

# # Connection pool Maximum number of connections (use negative values to indicate no limit)
spring.redis.pool.max-active=300
# # Redis Database index (default = 0)
spring.redis.database=0
# # Connection pool maximum blocking wait time (use negative value to indicate no limit)
Spring.redis.pool.max-wait=-1
# # Maximum idle connections in the connection pool
spring.redis.pool.max-idle=100
# # Minimum idle connections in the connection pool
spring.redis.pool.min-idle=20
# # Connection time-out (milliseconds)
spring.redis.timeout=60000

After Redis and session have been configured, the HttpSession information for each service is shared in the same Redis cache after using the distributed multi-server application.

Springboot session sharing (using Redis)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.