1
0
mirror of https://gitee.com/coder-xiaomo/flashsale synced 2025-01-10 19:58:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

Redis 分布式会话(基于session)

This commit is contained in:
程序员小墨 2022-03-07 17:43:40 +08:00
parent cfd3a6f029
commit b348a8c060
4 changed files with 35 additions and 2 deletions

12
pom.xml
View File

@ -80,6 +80,18 @@
<version>2.9.1</version> <version>2.9.1</version>
</dependency> </dependency>
<!--引入SpringBoot对Redis的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--SpringBoot将Session存储在Redis中-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,10 @@
package com.cxyxiaomo.flashsale.config;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.stereotype.Component;
@Component
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 3600) // 会话1hour过期
public class RedisConfig {
}

View File

@ -5,8 +5,9 @@ import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable;
public class UserModel { public class UserModel implements Serializable {
private Integer id; private Integer id;
@NotBlank(message = "用户名不能为空") @NotBlank(message = "用户名不能为空")

View File

@ -11,3 +11,13 @@ spring.datasource.password=111111
# 使用druid数据源 # 使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.driverClassName=com.mysql.jdbc.Driver
# 配置SpringBoot对Redis的依赖
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.database=10
#spring.redis.password=
# 设置jedis连接池
spring.redis.jedis.pool.max-active=50
spring.redis.jedis.pool.max-idle=20