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: