From b348a8c0604ea7d48b5d3b81490849ddd85634d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?=
<2291200076@qq.com>
Date: Mon, 7 Mar 2022 17:43:40 +0800
Subject: [PATCH] =?UTF-8?q?Redis=20=E5=88=86=E5=B8=83=E5=BC=8F=E4=BC=9A?=
=?UTF-8?q?=E8=AF=9D=EF=BC=88=E5=9F=BA=E4=BA=8Esession=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 12 ++++++++++++
.../com/cxyxiaomo/flashsale/config/RedisConfig.java | 10 ++++++++++
.../cxyxiaomo/flashsale/service/model/UserModel.java | 3 ++-
src/main/resources/application.properties | 12 +++++++++++-
4 files changed, 35 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/com/cxyxiaomo/flashsale/config/RedisConfig.java
diff --git a/pom.xml b/pom.xml
index 75752a3..1d2b605 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,18 @@
2.9.1
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+
+
+ org.springframework.session
+ spring-session-data-redis
+ 2.0.5.RELEASE
+
diff --git a/src/main/java/com/cxyxiaomo/flashsale/config/RedisConfig.java b/src/main/java/com/cxyxiaomo/flashsale/config/RedisConfig.java
new file mode 100644
index 0000000..a9e2212
--- /dev/null
+++ b/src/main/java/com/cxyxiaomo/flashsale/config/RedisConfig.java
@@ -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 {
+
+}
diff --git a/src/main/java/com/cxyxiaomo/flashsale/service/model/UserModel.java b/src/main/java/com/cxyxiaomo/flashsale/service/model/UserModel.java
index 9f14bfd..82f9cf9 100644
--- a/src/main/java/com/cxyxiaomo/flashsale/service/model/UserModel.java
+++ b/src/main/java/com/cxyxiaomo/flashsale/service/model/UserModel.java
@@ -5,8 +5,9 @@ import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
+import java.io.Serializable;
-public class UserModel {
+public class UserModel implements Serializable {
private Integer id;
@NotBlank(message = "用户名不能为空")
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 0fa7365..6c50aa0 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -10,4 +10,14 @@ spring.datasource.password=111111
# 使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
-spring.datasource.driverClassName=com.mysql.jdbc.Driver
\ No newline at end of file
+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