From 03fde3699bcfa4b5fc1b57f43bc8ab0b3e3a859b Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sat, 5 Dec 2020 19:49:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=20Redis=20Starter=202.?= =?UTF-8?q?=20=E5=9C=A8=20system-service-app=20=E5=BC=95=E5=85=A5=20Redis?= =?UTF-8?q?=20Starter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/mall-spring-boot-starter-redis/pom.xml | 21 ++++++ .../mall/redis/core/RedisKeyDefine.java | 71 +++++++++++++++++++ common/pom.xml | 1 + mall-dependencies/pom.xml | 12 ++++ .../system-service-app/pom.xml | 5 ++ .../src/main/resources/application-dev.yaml | 3 +- .../src/main/resources/application-local.yaml | 9 ++- 7 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 common/mall-spring-boot-starter-redis/pom.xml create mode 100644 common/mall-spring-boot-starter-redis/src/main/java/cn/iocoder/mall/redis/core/RedisKeyDefine.java diff --git a/common/mall-spring-boot-starter-redis/pom.xml b/common/mall-spring-boot-starter-redis/pom.xml new file mode 100644 index 000000000..479f37306 --- /dev/null +++ b/common/mall-spring-boot-starter-redis/pom.xml @@ -0,0 +1,21 @@ + + + + common + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + mall-spring-boot-starter-redis + + + + org.redisson + redisson-spring-boot-starter + + + + diff --git a/common/mall-spring-boot-starter-redis/src/main/java/cn/iocoder/mall/redis/core/RedisKeyDefine.java b/common/mall-spring-boot-starter-redis/src/main/java/cn/iocoder/mall/redis/core/RedisKeyDefine.java new file mode 100644 index 000000000..0ac7ece2d --- /dev/null +++ b/common/mall-spring-boot-starter-redis/src/main/java/cn/iocoder/mall/redis/core/RedisKeyDefine.java @@ -0,0 +1,71 @@ +package cn.iocoder.mall.redis.core; + +import java.time.Duration; + +/** + * Redis Key 定义类 + */ +public class RedisKeyDefine { + + public enum KeyTypeEnum { + + STRING, + LIST, + HASH, + SET, + ZSET, + STREAM, + PUBSUB; + + } + + /** + * 过期时间 - 永不过期 + */ + public static final Duration TIMEOUT_FOREVER = null; + + /** + * Key 模板 + */ + private final String keyTemplate; + /** + * Key 类型的枚举 + */ + private final KeyTypeEnum keyType; + /** + * Value 类型 + * + * 如果是使用分布式锁,设置为 {@link java.util.concurrent.locks.Lock} 类型 + */ + private final Class valueType; + /** + * 过期时间 + * + * 为空时,表示永不过期 {@link #TIMEOUT_FOREVER} + */ + private final Duration timeout; + + public RedisKeyDefine(String keyTemplate, KeyTypeEnum keyType, Class valueType, Duration timeout) { + this.keyTemplate = keyTemplate; + this.keyType = keyType; + this.valueType = valueType; + this.timeout = timeout; + } + + public String getKeyTemplate() { + return keyTemplate; + } + + public KeyTypeEnum getKeyType() { + return keyType; + } + + public Class getValueType() { + return valueType; + } + + public Duration getTimeout() { + return timeout; + } + +} diff --git a/common/pom.xml b/common/pom.xml index 109af83ba..3596975dc 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -25,6 +25,7 @@ mall-spring-boot-starter-system-error-code mall-spring-boot-starter-rocketmq mall-spring-boot-starter-xxl-job + mall-spring-boot-starter-redis diff --git a/mall-dependencies/pom.xml b/mall-dependencies/pom.xml index 069608c19..7e29514c7 100644 --- a/mall-dependencies/pom.xml +++ b/mall-dependencies/pom.xml @@ -40,6 +40,7 @@ 3.5.4 3.3.2 3.2.5.RELEASE + 3.13.6 2.7.7 @@ -145,11 +146,22 @@ ${spring-boot-starter-data-jest.version} + + org.redisson + redisson-spring-boot-starter + ${redisson.version} + + cn.iocoder.mall mall-spring-boot-starter-mybatis 1.0-SNAPSHOT + + cn.iocoder.mall + mall-spring-boot-starter-redis + 1.0-SNAPSHOT + diff --git a/system-service-project/system-service-app/pom.xml b/system-service-project/system-service-app/pom.xml index b5ad252e6..eb42f234e 100644 --- a/system-service-project/system-service-app/pom.xml +++ b/system-service-project/system-service-app/pom.xml @@ -56,6 +56,11 @@ mall-spring-boot-starter-mybatis + + cn.iocoder.mall + mall-spring-boot-starter-redis + + org.springframework.boot diff --git a/system-service-project/system-service-app/src/main/resources/application-dev.yaml b/system-service-project/system-service-app/src/main/resources/application-dev.yaml index 2214910e4..372800187 100644 --- a/system-service-project/system-service-app/src/main/resources/application-dev.yaml +++ b/system-service-project/system-service-app/src/main/resources/application-dev.yaml @@ -1,10 +1,11 @@ spring: - # 数据源配置项 + # MySQL 配置项 datasource: url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root password: 3WLiVUBEwTbvAfsh + # Spring Cloud 配置项 cloud: nacos: diff --git a/system-service-project/system-service-app/src/main/resources/application-local.yaml b/system-service-project/system-service-app/src/main/resources/application-local.yaml index b0bbbf8f9..adbbf576e 100644 --- a/system-service-project/system-service-app/src/main/resources/application-local.yaml +++ b/system-service-project/system-service-app/src/main/resources/application-local.yaml @@ -1,10 +1,17 @@ spring: - # 数据源配置项 + # MySQL 配置项 datasource: url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root password: 3WLiVUBEwTbvAfsh + + # Redis 配置 + redis: + host: 127.0.0.1 + port: 6379 + database: 0 + # Spring Cloud 配置项 cloud: nacos: