ソースを参照

feat: 添加redis相关配置与依赖

yangliu 3 ヶ月 前
コミット
6c04cdd4ac
24 ファイル変更684 行追加1126 行削除
  1. 0 165
      knife4j-doc-spring-boot-starter/README.md
  2. 0 27
      knife4j-doc-spring-boot-starter/pom.xml
  3. 0 52
      knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/base/BaseSwaggerConfig.java
  4. 0 55
      knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/base/SwaggerProperties.java
  5. 0 98
      knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/configure/DocAutoConfigure.java
  6. 0 70
      knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/gateway/Knife4jGatewayConfig.java
  7. 0 108
      knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/properties/DocProperties.java
  8. 0 3
      knife4j-doc-spring-boot-starter/src/main/resources/META-INF/spring.factories
  9. 7 10
      pom.xml
  10. 60 0
      redis-spring-boot-starter/pom.xml
  11. 27 0
      redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/autoconfigure/AutoRedisConfiguration.java
  12. 28 0
      redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/properties/RedisProperties.java
  13. 114 0
      redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/util/RedisUtil.java
  14. 2 0
      redis-spring-boot-starter/src/main/resources/META-INF/spring.factories
  15. 8 0
      redis-spring-boot-starter/src/test/java/cn/hfln/framework/redis/RedisTestApplication.java
  16. 23 0
      redis-spring-boot-starter/src/test/java/cn/hfln/framework/redis/RedisUtilIntegrationTest.java
  17. 1 6
      src/main/java/cn/hfln/framework/gateway/GatewayApplication.java
  18. 0 32
      src/main/java/cn/hfln/framework/gateway/componet/ResultHandler.java
  19. 44 44
      src/main/java/cn/hfln/framework/gateway/config/FastJson2JsonRedisSerializer.java
  20. 0 20
      src/main/java/cn/hfln/framework/gateway/config/Knife4jDocGroupConfig.java
  21. 0 40
      src/main/java/cn/hfln/framework/gateway/config/Knife4jGatewayConfig.java
  22. 11 38
      src/main/java/cn/hfln/framework/gateway/config/RedisConfig.java
  23. 355 355
      src/main/java/cn/hfln/framework/gateway/config/RedisService.java
  24. 4 3
      src/main/java/cn/hfln/framework/gateway/config/StpInterfaceImpl.java

+ 0 - 165
knife4j-doc-spring-boot-starter/README.md

@@ -1,165 +0,0 @@
-# Knife4j Doc Starter 使用说明
-
-基于 Knife4j 4.x + OpenAPI 3 规范的接口文档增强解决方案。
-
-## 特性
-
-- 基于 OpenAPI 3 规范
-- 支持 Spring Cloud Gateway 网关聚合文档
-- 支持 JWT 等安全认证配置
-- 支持接口分组管理
-- 支持中文界面
-
-## 快速开始
-
-### 1. 微服务中使用
-
-在需要暴露 API 文档的微服务的 `pom.xml` 中添加依赖:
-
-```xml
-<dependency>
-    <groupId>cn.hfln.framework</groupId>
-    <artifactId>knife4j-doc-spring-boot-starter</artifactId>
-    <version>${project.version}</version>
-</dependency>
-```
-
-在 `application.yml` 中添加配置:
-
-```yaml
-lnxx:
-  knife4j:
-    doc:
-      enable: true
-      base-package: com.your.package  # 接口所在包路径
-      title: 服务名称
-      description: 服务描述
-      version: ${project.version}
-      enable-security: true  # 是否启用安全认证
-```
-
-### 2. Gateway 网关中使用
-
-#### 2.1 添加依赖
-
-在网关项目的 `pom.xml` 中添加依赖:
-
-```xml
-<dependency>
-    <groupId>cn.hfln.framework</groupId>
-    <artifactId>knife4j-doc-spring-boot-starter</artifactId>
-    <version>${project.version}</version>
-</dependency>
-```
-
-#### 2.2 网关配置
-
-在网关的 `application.yml` 中添加如下配置:
-
-```yaml
-spring:
-  cloud:
-    gateway:
-      routes:
-        # 文档聚合路由
-        - id: knife4j
-          uri: http://localhost:${server.port}
-          predicates:
-            - Path=/v3/api-docs/**
-          filters:
-            - RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/v3/api-docs
-
-lnxx:
-  knife4j:
-    doc:
-      enable: true
-      title: API 文档中心
-      description: 微服务接口文档
-      version: ${project.version}
-      enable-security: true
-
-# 配置需要聚合的微服务文档
-springdoc:
-  swagger-ui:
-    path: /doc.html
-  api-docs:
-    enabled: true
-  group-configs:
-    - group: 'default'
-      paths-to-match: '/**'
-      packages-to-scan: cn.hfln
-```
-
-#### 2.3 创建网关聚合配置类
-
-```java
-@Configuration
-public class Knife4jGatewayConfig {
-    
-    @Bean
-    public RouterFunction<ServerResponse> apiRouter() {
-        return RouterFunctions.route()
-            .GET("/v3/api-docs/swagger-config", request ->
-                ServerResponse.ok().bodyValue(swaggerConfig()))
-            .build();
-    }
-
-    private Map<String, Object> swaggerConfig() {
-        Map<String, Object> config = new HashMap<>();
-        // 配置要聚合的微服务,key 为服务名,value 为文档地址
-        Map<String, String> services = new HashMap<>();
-        services.put("用户服务", "/user-service/v3/api-docs");
-        services.put("订单服务", "/order-service/v3/api-docs");
-        // ... 添加更多服务
-        
-        config.put("urls", services);
-        return config;
-    }
-}
-```
-
-### 3. 访问文档
-
-- 单个服务文档地址:`http://服务地址:端口/doc.html`
-- 网关聚合文档地址:`http://网关地址:端口/doc.html`
-
-## 注意事项
-
-1. 网关聚合时,确保所有微服务的 OpenAPI 文档都已启用
-2. 如果启用了安全认证,需要在 Swagger UI 界面配置对应的认证信息
-3. 建议在生产环境关闭或限制文档访问
-4. 网关层建议配置文档访问的路由限制
-
-## 常见问题
-
-1. 文档无法访问
-   - 检查服务是否正常启动
-   - 检查网关路由配置是否正确
-   - 检查安全认证配置
-
-2. 网关聚合失败
-   - 检查微服务的文档地址是否可访问
-   - 检查网关路由配置是否正确
-   - 检查网络连通性
-
-3. 认证失败
-   - 检查认证配置是否正确
-   - 确认 Token 格式是否正确
-   - 检查认证服务是否正常
-
-## 配置说明
-
-| 配置项 | 说明 | 默认值 |
-|-------|------|--------|
-| lnxx.knife4j.doc.enable | 是否启用文档 | true |
-| lnxx.knife4j.doc.base-package | 接口扫描包路径 | - |
-| lnxx.knife4j.doc.title | 文档标题 | API 文档 |
-| lnxx.knife4j.doc.description | 文档描述 | - |
-| lnxx.knife4j.doc.version | 文档版本 | 1.0.0 |
-| lnxx.knife4j.doc.enable-security | 是否启用安全认证 | false |
-
-## 版本说明
-
-- 基于 Knife4j 4.x
-- 支持 Spring Boot 2.6.x 及以上版本
-- 支持 Spring Cloud 2021.x 及以上版本

+ 0 - 27
knife4j-doc-spring-boot-starter/pom.xml

@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>hfln-framework-design-starter</artifactId>
-        <groupId>cn.hfln.framework</groupId>
-        <version>1.0.0-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>knife4j-doc-spring-boot-starter</artifactId>
-
-    <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
-    </properties>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.github.xiaoymin</groupId>
-            <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
-            <version>${knife4j.version}</version>
-        </dependency>
-    </dependencies>
-
-</project>

+ 0 - 52
knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/base/BaseSwaggerConfig.java

@@ -1,52 +0,0 @@
-package cn.hfln.framework.knife4j.doc.base;
-
-import io.swagger.v3.oas.models.Components;
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Contact;
-import io.swagger.v3.oas.models.info.Info;
-import io.swagger.v3.oas.models.security.SecurityRequirement;
-import io.swagger.v3.oas.models.security.SecurityScheme;
-import io.swagger.v3.oas.models.servers.Server;
-import java.util.Collections;
-
-/**
- * @USER: YangLiu
- * @DESC: 基础 Swagger 配置类,供其他模块继承和自定义
- */
-public abstract class BaseSwaggerConfig {
-    
-    /**
-     * 自定义Swagger配置
-     */
-    public abstract SwaggerProperties swaggerProperties();
-
-    /**
-     * 创建自定义的 OpenAPI 配置
-     */
-    protected OpenAPI createOpenAPI(SwaggerProperties swaggerProperties) {
-        OpenAPI openAPI = new OpenAPI()
-                .info(new Info()
-                        .title(swaggerProperties.getTitle())
-                        .description(swaggerProperties.getDescription())
-                        .version(swaggerProperties.getVersion())
-                        .contact(new Contact()
-                                .name(swaggerProperties.getContactName())
-                                .url(swaggerProperties.getContactUrl())
-                                .email(swaggerProperties.getContactEmail())));
-
-        if (swaggerProperties.getServerUrl() != null && !swaggerProperties.getServerUrl().isEmpty()) {
-            openAPI.setServers(Collections.singletonList(new Server().url(swaggerProperties.getServerUrl())));
-        }
-
-        if (swaggerProperties.isEnableSecurity()) {
-            openAPI.addSecurityItem(new SecurityRequirement().addList("Authorization"))
-                    .components(new Components()
-                            .addSecuritySchemes("Authorization",
-                                    new SecurityScheme()
-                                            .type(SecurityScheme.Type.HTTP)
-                                            .scheme("bearer")
-                                            .bearerFormat("JWT")));
-        }
-        return openAPI;
-    }
-}

+ 0 - 55
knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/base/SwaggerProperties.java

@@ -1,55 +0,0 @@
-package cn.hfln.framework.knife4j.doc.base;
-
-import lombok.Builder;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * @USER: YangLiu
- * @DESC:
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Builder
-public class SwaggerProperties {
-    /**
-     * API文档生成基础路径
-     */
-    private String apiBasePackage;
-    /**
-     * 是否要启用登录认证
-     */
-    private boolean enableSecurity;
-    /**
-     * 文档标题
-     */
-    private String title;
-    /**
-     * 文档描述
-     */
-    private String description;
-    /**
-     * 文档版本
-     */
-    private String version;
-    /**
-     * 文档联系人姓名
-     */
-    private String contactName;
-    /**
-     * 文档联系人网址
-     */
-    private String contactUrl;
-    /**
-     * 文档联系人邮箱
-     */
-    private String contactEmail;
-    /**
-     * API 分组名称
-     */
-    private String group;
-    /**
-     * OpenAPI servers 字段,支持网关前缀
-     */
-    private String serverUrl;
-}

+ 0 - 98
knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/configure/DocAutoConfigure.java

@@ -1,98 +0,0 @@
-package cn.hfln.framework.knife4j.doc.configure;
-
-import cn.hfln.framework.knife4j.doc.base.BaseSwaggerConfig;
-import cn.hfln.framework.knife4j.doc.base.SwaggerProperties;
-import cn.hfln.framework.knife4j.doc.properties.DocProperties;
-import io.swagger.v3.oas.models.OpenAPI;
-import io.swagger.v3.oas.models.info.Contact;
-import io.swagger.v3.oas.models.info.Info;
-import io.swagger.v3.oas.models.info.License;
-import io.swagger.v3.oas.models.Components;
-import io.swagger.v3.oas.models.security.SecurityRequirement;
-import io.swagger.v3.oas.models.security.SecurityScheme;
-import io.swagger.v3.oas.models.servers.Server;
-import org.springdoc.core.SpringDocConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.context.annotation.Primary;
-
-import java.util.stream.Collectors;
-
-/**
- * @USER: YangLiu
- * knife4j 接口文档配置
- */
-@Configuration
-@EnableConfigurationProperties(DocProperties.class)
-@ConditionalOnProperty(value = "lnxx.knife4j.doc.enable", havingValue = "true", matchIfMissing = true)
-@Import(SpringDocConfiguration.class)
-public class DocAutoConfigure extends BaseSwaggerConfig {
-
-    private final DocProperties properties;
-
-    public DocAutoConfigure(DocProperties properties) {
-        this.properties = properties;
-    }
-
-    @Bean
-    @Primary
-    @ConditionalOnMissingBean
-    public OpenAPI customOpenAPI() {
-        OpenAPI openAPI = new OpenAPI()
-                .info(new Info()
-                        .title(properties.getTitle())
-                        .description(String.format("<div style='font-size:%spx;color:%s;'>%s</div>",
-                                properties.getDescriptionFontSize(), properties.getDescriptionColor(), properties.getDescription()))
-                        .version(properties.getVersion())
-                        .contact(new Contact()
-                                .name(properties.getName())
-                                .url(properties.getUrl())
-                                .email(properties.getEmail()))
-                        .license(new License()
-                                .name(properties.getLicense())
-                                .url(properties.getLicenseUrl()))
-                        .termsOfService(properties.getTermsOfServiceUrl()));
-
-        // 只使用 yml 配置的 servers 字段,不设置默认 server
-        if (properties.getServers() != null && !properties.getServers().isEmpty()) {
-            openAPI.setServers(properties.getServers().stream()
-                    .map(cfg -> new Server().url(cfg.getUrl()).description(cfg.getDescription()))
-                    .collect(Collectors.toList()));
-        }
-
-        if (properties.isEnableSecurity()) {
-            openAPI.addSecurityItem(new SecurityRequirement().addList("Bearer"))
-                    .components(new Components()
-                            .addSecuritySchemes("Bearer",
-                                    new SecurityScheme()
-                                            .type(SecurityScheme.Type.HTTP)
-                                            .scheme("bearer")
-                                            .bearerFormat("JWT")
-                                            .in(SecurityScheme.In.HEADER)
-                                            .name("Authorization")));
-        }
-
-        return openAPI;
-    }
-
-    @Override
-    public SwaggerProperties swaggerProperties() {
-        return SwaggerProperties.builder()
-                .apiBasePackage(properties.getBasePackage())
-                .title(properties.getTitle())
-                .description(String.format("<div style='font-size:%spx;color:%s;'>%s</div>",
-                        properties.getDescriptionFontSize(), properties.getDescriptionColor(), properties.getDescription()))
-                .version(properties.getVersion())
-                .contactName(properties.getName())
-                .contactUrl(properties.getUrl())
-                .contactEmail(properties.getEmail())
-                .enableSecurity(properties.isEnableSecurity())
-                .group("default")
-                .serverUrl(properties.getServerUrl())
-                .build();
-    }
-}

+ 0 - 70
knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/gateway/Knife4jGatewayConfig.java

@@ -1,70 +0,0 @@
-package cn.hfln.framework.knife4j.doc.gateway;
-
-import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.reactive.function.server.RouterFunction;
-import org.springframework.web.reactive.function.server.RouterFunctions;
-import org.springframework.web.reactive.function.server.ServerResponse;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Gateway 网关 Knife4j 聚合配置示例
- * 仅在 WebFlux 环境下生效
- */
-@Configuration
-@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
-public class Knife4jGatewayConfig {
-
-    @Bean
-    public RouterFunction<ServerResponse> apiRouter() {
-        return RouterFunctions.route()
-                .GET("/v3/api-docs/swagger-config", request ->
-                        ServerResponse.ok().bodyValue(swaggerConfig()))
-                .build();
-    }
-
-    private Map<String, Object> swaggerConfig() {
-        Map<String, Object> config = new HashMap<>(8);
-        config.put("urls", buildServiceUrls());
-        return config;
-    }
-
-    private List<ServiceUrl> buildServiceUrls() {
-        List<ServiceUrl> serviceUrls = new ArrayList<>();
-        // 这里添加需要聚合的服务,实际项目中可以从注册中心动态获取
-        serviceUrls.add(new ServiceUrl("用户服务", "/user-service/v3/api-docs"));
-        serviceUrls.add(new ServiceUrl("订单服务", "/order-service/v3/api-docs"));
-        return serviceUrls;
-    }
-
-    static class ServiceUrl {
-        private String name;
-        private String url;
-
-        public ServiceUrl(String name, String url) {
-            this.name = name;
-            this.url = url;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public String getUrl() {
-            return url;
-        }
-
-        public void setUrl(String url) {
-            this.url = url;
-        }
-    }
-} 

+ 0 - 108
knife4j-doc-spring-boot-starter/src/main/java/cn/hfln/framework/knife4j/doc/properties/DocProperties.java

@@ -1,108 +0,0 @@
-package cn.hfln.framework.knife4j.doc.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @USER: YangLiu
- */
-@ConfigurationProperties(prefix = "lnxx.knife4j.doc")
-@Data
-public class DocProperties {
-
-    /**
-     * 是否开启doc功能
-     */
-    private Boolean enable = true;
-    /**
-     * 接口扫描路径,如Controller路径
-     */
-    private String basePackage;
-
-
-    /**
-     * 是否要启用登录认证
-     */
-    private boolean enableSecurity = false;
-
-    /**
-     * 文档标题
-     */
-    private String title;
-    /**
-     * 文档描述
-     */
-    private String description;
-    /**
-     * 文档描述颜色
-     */
-    private String descriptionColor = "#42b983";
-    /**
-     * 文档描述字体大小
-     */
-    private String descriptionFontSize = "14";
-    /**
-     * 服务url
-     */
-    private String termsOfServiceUrl;
-    /**
-     * 联系方式:姓名
-     */
-    private String name;
-    /**
-     * 联系方式:个人网站url
-     */
-    private String url;
-    /**
-     * 联系方式:邮箱
-     */
-    private String email;
-    /**
-     * 协议
-     */
-    private String license;
-    /**
-     * 协议地址
-     */
-    private String licenseUrl;
-    /**
-     * 版本
-     */
-    private String version;
-
-    /**
-     * 网关前缀(OpenAPI servers 字段)
-     */
-    private String serverUrl;
-
-    /**
-     * 支持yml多server配置
-     */
-    private java.util.List<ServerConfig> servers;
-
-    @lombok.Data
-    public static class ServerConfig {
-        private String url;
-        private String description;
-    }
-
-    @Override
-    public String toString() {
-        return "DocProperties{" +
-                "enable=" + enable +
-                ", basePackage='" + basePackage + '\'' +
-                ", title='" + title + '\'' +
-                ", description='" + description + '\'' +
-                ", descriptionColor='" + descriptionColor + '\'' +
-                ", descriptionFontSize='" + descriptionFontSize + '\'' +
-                ", termsOfServiceUrl='" + termsOfServiceUrl + '\'' +
-                ", name='" + name + '\'' +
-                ", url='" + url + '\'' +
-                ", email='" + email + '\'' +
-                ", license='" + license + '\'' +
-                ", licenseUrl='" + licenseUrl + '\'' +
-                ", version='" + version + '\'' +
-                ", serverUrl='" + serverUrl + '\'' +
-                '}';
-    }
-}

+ 0 - 3
knife4j-doc-spring-boot-starter/src/main/resources/META-INF/spring.factories

@@ -1,3 +0,0 @@
-# Auto Configure
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-cn.hfln.framework.knife4j.doc.configure.DocAutoConfigure

+ 7 - 10
pom.xml

@@ -41,6 +41,7 @@
                 <scope>import</scope>
             </dependency>
         </dependencies>
+
     </dependencyManagement>
 
     <dependencies>
@@ -51,6 +52,11 @@
         </dependency>
         <dependency>
             <groupId>cn.hfln.framework</groupId>
+            <artifactId>redis-spring-boot-starter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hfln.framework</groupId>
             <artifactId>hfln-framework-exception</artifactId>
             <version>1.0.0-SNAPSHOT</version>
         </dependency>
@@ -132,11 +138,7 @@
 <!--            <version>1.6.15</version>-->
 <!--        </dependency>-->
 
-        <dependency>
-            <groupId>com.github.xiaoymin</groupId>
-            <artifactId>knife4j-openapi3-ui</artifactId>
-            <version>4.1.0</version>
-        </dependency>
+
 
         <!-- Sa-Token 权限认证(Reactor响应式集成), 在线文档:https://sa-token.cc -->
         <dependency>
@@ -155,11 +157,6 @@
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-pool2</artifactId>
         </dependency>
-        <!-- SpringBoot Boot Redis -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
-        </dependency>
     </dependencies>
 
     <build>

+ 60 - 0
redis-spring-boot-starter/pom.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>hfln-framework-design-starter</artifactId>
+        <groupId>cn.hfln.framework</groupId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>redis-spring-boot-starter</artifactId>
+    <name>redis-spring-boot-starter</name>
+    <description>通用 Redis Starter,自动装配,支持常用 Redis 操作</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <!-- Jackson 依赖 -->
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+        </dependency>
+        <!-- 测试依赖 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project> 

+ 27 - 0
redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/autoconfigure/AutoRedisConfiguration.java

@@ -0,0 +1,27 @@
+package cn.hfln.framework.redis.autoconfigure;
+
+import cn.hfln.framework.redis.util.RedisUtil;
+import cn.hfln.framework.redis.properties.RedisProperties;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
+
+@Configuration
+@AutoConfigureAfter(name = "org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration")
+@EnableConfigurationProperties(RedisProperties.class)
+public class AutoRedisConfiguration {
+
+    public AutoRedisConfiguration() {
+        System.out.println("【RedisAutoConfiguration】构造方法被调用");
+    }
+
+    @Bean
+    @ConditionalOnBean(RedisTemplate.class)
+    public RedisUtil redisUtil(RedisTemplate<String, Object> redisTemplate, RedisProperties redisProperties) {
+        System.out.println("【RedisAutoConfiguration】redisUtil Bean 创建");
+        return new RedisUtil(redisTemplate, redisProperties);
+    }
+}

+ 28 - 0
redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/properties/RedisProperties.java

@@ -0,0 +1,28 @@
+package cn.hfln.framework.redis.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "hfln.redis")
+public class RedisProperties {
+    /**
+     * key 前缀
+     */
+    private String keyPrefix = "";
+    /**
+     * 默认超时时间(秒)
+     */
+    private long defaultTimeout = 3600;
+
+    public String getKeyPrefix() {
+        return keyPrefix;
+    }
+    public void setKeyPrefix(String keyPrefix) {
+        this.keyPrefix = keyPrefix;
+    }
+    public long getDefaultTimeout() {
+        return defaultTimeout;
+    }
+    public void setDefaultTimeout(long defaultTimeout) {
+        this.defaultTimeout = defaultTimeout;
+    }
+} 

+ 114 - 0
redis-spring-boot-starter/src/main/java/cn/hfln/framework/redis/util/RedisUtil.java

@@ -0,0 +1,114 @@
+package cn.hfln.framework.redis.util;
+
+import cn.hfln.framework.redis.properties.RedisProperties;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Redis 工具类,封装常用操作,支持 key 前缀、默认超时、分布式锁等
+ */
+public class RedisUtil {
+    private final RedisTemplate<String, Object> redisTemplate;
+    private final RedisProperties redisProperties;
+
+    public RedisUtil(RedisTemplate<String, Object> redisTemplate, RedisProperties redisProperties) {
+        System.out.println("【RedisUtil】构造方法被调用");
+        this.redisTemplate = redisTemplate;
+        this.redisProperties = redisProperties;
+    }
+
+    private String wrapKey(String key) {
+        String prefix = redisProperties != null ? redisProperties.getKeyPrefix() : "";
+        return prefix + key;
+    }
+
+    // ============================= String ============================
+    public void set(String key, Object value) {
+        set(key, value, redisProperties != null ? redisProperties.getDefaultTimeout() : 3600, TimeUnit.SECONDS);
+    }
+    public void set(String key, Object value, long timeout, TimeUnit unit) {
+        redisTemplate.opsForValue().set(wrapKey(key), value, timeout, unit);
+    }
+    public Object get(String key) {
+        return redisTemplate.opsForValue().get(wrapKey(key));
+    }
+    public boolean del(String key) {
+        return Boolean.TRUE.equals(redisTemplate.delete(wrapKey(key)));
+    }
+
+    // ============================= Hash =============================
+    public void hSet(String key, String field, Object value) {
+        redisTemplate.opsForHash().put(wrapKey(key), field, value);
+    }
+    public Object hGet(String key, String field) {
+        return redisTemplate.opsForHash().get(wrapKey(key), field);
+    }
+    public Map<Object, Object> hGetAll(String key) {
+        return redisTemplate.opsForHash().entries(wrapKey(key));
+    }
+    public void hDel(String key, String... fields) {
+        redisTemplate.opsForHash().delete(wrapKey(key), (Object[]) fields);
+    }
+
+    // ============================= List =============================
+    public void lPush(String key, Object value) {
+        redisTemplate.opsForList().leftPush(wrapKey(key), value);
+    }
+    public Object lPop(String key) {
+        return redisTemplate.opsForList().leftPop(wrapKey(key));
+    }
+    public List<Object> lRange(String key, long start, long end) {
+        return redisTemplate.opsForList().range(wrapKey(key), start, end);
+    }
+
+    // ============================= Set ==============================
+    public void sAdd(String key, Object... values) {
+        redisTemplate.opsForSet().add(wrapKey(key), values);
+    }
+    public Set<Object> sMembers(String key) {
+        return redisTemplate.opsForSet().members(wrapKey(key));
+    }
+    public boolean sIsMember(String key, Object value) {
+        return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(wrapKey(key), value));
+    }
+
+    // ============================= ZSet =============================
+    public void zAdd(String key, Object value, double score) {
+        redisTemplate.opsForZSet().add(wrapKey(key), value, score);
+    }
+    public Set<Object> zRange(String key, long start, long end) {
+        return redisTemplate.opsForZSet().range(wrapKey(key), start, end);
+    }
+
+    // ============================= 通用 =============================
+    public boolean expire(String key, long timeout, TimeUnit unit) {
+        return Boolean.TRUE.equals(redisTemplate.expire(wrapKey(key), timeout, unit));
+    }
+    public long getExpire(String key, TimeUnit unit) {
+        return redisTemplate.getExpire(wrapKey(key), unit);
+    }
+    public boolean hasKey(String key) {
+        return Boolean.TRUE.equals(redisTemplate.hasKey(wrapKey(key)));
+    }
+
+    // ============================= 原子操作 =========================
+    public Long incr(String key) {
+        return redisTemplate.opsForValue().increment(wrapKey(key));
+    }
+    public Long incrBy(String key, long delta) {
+        return redisTemplate.opsForValue().increment(wrapKey(key), delta);
+    }
+
+    // ============================= 分布式锁(简单实现) =============
+    public boolean tryLock(String key, String value, long timeout, TimeUnit unit) {
+        Boolean success = redisTemplate.opsForValue().setIfAbsent(wrapKey(key), value, timeout, unit);
+        return Boolean.TRUE.equals(success);
+    }
+    public void unlock(String key) {
+        del(key);
+    }
+} 

+ 2 - 0
redis-spring-boot-starter/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,2 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+cn.hfln.framework.redis.autoconfigure.AutoRedisConfiguration

+ 8 - 0
redis-spring-boot-starter/src/test/java/cn/hfln/framework/redis/RedisTestApplication.java

@@ -0,0 +1,8 @@
+package cn.hfln.framework.redis;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class RedisTestApplication {
+    // 仅用于测试上下文启动,无需实现内容
+} 

+ 23 - 0
redis-spring-boot-starter/src/test/java/cn/hfln/framework/redis/RedisUtilIntegrationTest.java

@@ -0,0 +1,23 @@
+package cn.hfln.framework.redis;
+
+import cn.hfln.framework.redis.util.RedisUtil;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@SpringBootTest(classes = RedisTestApplication.class)
+class RedisUtilIntegrationTest {
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Test
+    void testSetGetDel() {
+        redisUtil.set("testKey", "testValue");
+        Object value = redisUtil.get("testKey");
+        assertEquals("testValue", value);
+        redisUtil.del("testKey");
+    }
+} 

+ 1 - 6
src/main/java/cn/hfln/framework/gateway/GatewayApplication.java

@@ -2,14 +2,9 @@ package cn.hfln.framework.gateway;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 
-@SpringBootApplication(
-    scanBasePackages = {"cn.hfln.framework.gateway"}
-//        , exclude = {RedisAutoConfiguration.class
-//    }
-)
+@SpringBootApplication
 @EnableDiscoveryClient
 public class GatewayApplication {
 

+ 0 - 32
src/main/java/cn/hfln/framework/gateway/componet/ResultHandler.java

@@ -1,32 +0,0 @@
-package cn.hfln.framework.gateway.componet;
-
-import cn.hutool.json.JSONUtil;
-import cn.hfln.framework.dto.ApiResult;
-import com.alibaba.fastjson2.JSON;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-/**
- * @USER: YangLiu
- */
-@Slf4j
-public class ResultHandler {
-    public Mono<Void> handle(ServerWebExchange exchange, Exception denied) {
-        ServerHttpResponse response = exchange.getResponse();
-        response.setStatusCode(HttpStatus.OK);
-        response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
-        response.getHeaders().set("Access-Control-Allow-Origin", "*");
-        response.getHeaders().set("Cache-Control", "no-cache");
-        String body = JSONUtil.toJsonStr(denied.getMessage());
-        log.info("认证错误!!! 错误信息:{}", body);
-        ApiResult<?> result = ApiResult.unauthorized(null);
-        DataBuffer buffer = response.bufferFactory().wrap(JSON.toJSONString(result).getBytes());
-        return response.writeWith(Mono.just(buffer));
-    }
-}

+ 44 - 44
src/main/java/cn/hfln/framework/gateway/config/FastJson2JsonRedisSerializer.java

@@ -1,44 +1,44 @@
-package cn.hfln.framework.gateway.config;
-
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONReader;
-import com.alibaba.fastjson2.JSONWriter;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.data.redis.serializer.SerializationException;
-
-import java.nio.charset.Charset;
-
-/**
- * Redis使用FastJson序列化
- *
- * @author cw
- */
-public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
-    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
-
-    private Class<T> clazz;
-
-
-    public FastJson2JsonRedisSerializer(Class<T> clazz) {
-        super();
-        this.clazz = clazz;
-    }
-
-    @Override
-    public byte[] serialize(T t) throws SerializationException {
-        if (t == null) {
-            return new byte[0];
-        }
-        return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
-    }
-
-    @Override
-    public T deserialize(byte[] bytes) throws SerializationException {
-        if (bytes == null || bytes.length <= 0) {
-            return null;
-        }
-        String str = new String(bytes, DEFAULT_CHARSET);
-
-        return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
-    }
-}
+//package cn.hfln.framework.gateway.config;
+//
+//import com.alibaba.fastjson2.JSON;
+//import com.alibaba.fastjson2.JSONReader;
+//import com.alibaba.fastjson2.JSONWriter;
+//import org.springframework.data.redis.serializer.RedisSerializer;
+//import org.springframework.data.redis.serializer.SerializationException;
+//
+//import java.nio.charset.Charset;
+//
+///**
+// * Redis使用FastJson序列化
+// *
+// * @author cw
+// */
+//public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
+//    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+//
+//    private Class<T> clazz;
+//
+//
+//    public FastJson2JsonRedisSerializer(Class<T> clazz) {
+//        super();
+//        this.clazz = clazz;
+//    }
+//
+//    @Override
+//    public byte[] serialize(T t) throws SerializationException {
+//        if (t == null) {
+//            return new byte[0];
+//        }
+//        return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
+//    }
+//
+//    @Override
+//    public T deserialize(byte[] bytes) throws SerializationException {
+//        if (bytes == null || bytes.length <= 0) {
+//            return null;
+//        }
+//        String str = new String(bytes, DEFAULT_CHARSET);
+//
+//        return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
+//    }
+//}

+ 0 - 20
src/main/java/cn/hfln/framework/gateway/config/Knife4jDocGroupConfig.java

@@ -1,20 +0,0 @@
-package cn.hfln.framework.gateway.config;
-
-import org.springdoc.core.SwaggerUiConfigParameters;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class Knife4jDocGroupConfig {
-
-    @Bean
-    public CommandLineRunner addGroups(SwaggerUiConfigParameters swaggerUiConfigParameters) {
-        return args -> {
-            // 添加下游服务分组
-            swaggerUiConfigParameters.addGroup("门户服务", "/portal-service-server/v3/api-docs");
-            // 如有更多服务,继续添加
-            // swaggerUiConfigParameters.addGroup("订单服务", "/order-service/v3/api-docs");
-        };
-    }
-} 

+ 0 - 40
src/main/java/cn/hfln/framework/gateway/config/Knife4jGatewayConfig.java

@@ -1,40 +0,0 @@
-package cn.hfln.framework.gateway.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.reactive.function.server.RouterFunction;
-import org.springframework.web.reactive.function.server.RouterFunctions;
-import org.springframework.web.reactive.function.server.ServerResponse;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Configuration
-public class Knife4jGatewayConfig {
-
-    @Bean
-    public RouterFunction<ServerResponse> apiRouter() {
-        return RouterFunctions.route()
-            .GET("/v3/api-docs/swagger-config", request ->
-                ServerResponse.ok().bodyValue(swaggerConfig()))
-            .build();
-    }
-
-    private Map<String, Object> swaggerConfig() {
-        Map<String, Object> config = new HashMap<>();
-        List<Map<String, String>> urls = new ArrayList<>();
-        Map<String, String> portal = new HashMap<>();
-        portal.put("name", "门户服务");
-        portal.put("url", "/portal-service-server/v3/api-docs");
-        urls.add(portal);
-        // 如有更多服务,继续添加
-        // Map<String, String> order = new HashMap<>();
-        // order.put("name", "订单服务");
-        // order.put("url", "/order-service/v3/api-docs");
-        // urls.add(order);
-        config.put("urls", urls);
-        return config;
-    }
-} 

+ 11 - 38
src/main/java/cn/hfln/framework/gateway/config/RedisConfig.java

@@ -1,58 +1,31 @@
 package cn.hfln.framework.gateway.config;
 
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
-import org.springframework.cache.annotation.CachingConfigurerSupport;
-import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.listener.RedisMessageListenerContainer;
 import org.springframework.data.redis.serializer.StringRedisSerializer;
 
 /**
- * redis配置
- *
- * @author cw
+ * Redis 配置类
+ * 手动注册 RedisTemplate,确保与自研 Redis Starter 兼容
  */
 @Configuration
-@EnableCaching
-//@AutoConfigureBefore(RedisAutoConfiguration.class)
-public class RedisConfig extends CachingConfigurerSupport {
-
+public class RedisConfig {
 
     @Bean
-    @SuppressWarnings(value = {"unchecked", "rawtypes"})
-    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
-        RedisTemplate<Object, Object> template = new RedisTemplate<>();
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
         template.setConnectionFactory(connectionFactory);
 
-        FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
-
-        // 使用StringRedisSerializer来序列化和反序列化redis的key值
-        template.setKeySerializer(new StringRedisSerializer());
-        template.setValueSerializer(serializer);
-
-        // Hash的key也采用StringRedisSerializer的序列化方式
-        template.setHashKeySerializer(new StringRedisSerializer());
-        template.setHashValueSerializer(serializer);
+        // 使用 StringRedisSerializer 进行序列化
+        StringRedisSerializer stringSerializer = new StringRedisSerializer();
+        template.setKeySerializer(stringSerializer);
+        template.setValueSerializer(stringSerializer);
+        template.setHashKeySerializer(stringSerializer);
+        template.setHashValueSerializer(stringSerializer);
 
         template.afterPropertiesSet();
         return template;
     }
-
-    @Bean
-    public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory factory) {
-        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
-
-        container.setConnectionFactory(factory);
-
-        //  container.setTaskExecutor(null);            // 设置用于执行监听器方法的 Executor
-        //  container.setErrorHandler(null);            // 设置监听器方法执行过程中出现异常的处理器
-        //  container.addMessageListener(null, null);   // 手动设置监听器 & 监听的 topic 表达式
-        return container;
-    }
 }

+ 355 - 355
src/main/java/cn/hfln/framework/gateway/config/RedisService.java

@@ -1,355 +1,355 @@
-package cn.hfln.framework.gateway.config;
-
-import cn.hutool.core.util.RandomUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.data.redis.core.BoundSetOperations;
-import org.springframework.data.redis.core.HashOperations;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.ValueOperations;
-import org.springframework.stereotype.Component;
-
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-/**
- * spring redis 工具类
- *
- * @author cw
- **/
-@SuppressWarnings(value = {"unchecked", "rawtypes"})
-@Component
-public class RedisService implements CommandLineRunner {
-    @Autowired
-    public RedisTemplate redisTemplate;
-
-    /**
-     * 缓存基本的对象,Integer、String、实体类等
-     *
-     * @param key   缓存的键值
-     * @param value 缓存的值
-     */
-    public <T> void setCacheObject(final String key, final T value) {
-        redisTemplate.opsForValue().set(key, value);
-    }
-
-    /**
-     * 分布式锁
-     *
-     * @param key
-     * @param value
-     * @return
-     */
-    public boolean setNx(final String key, String value) {
-        return redisTemplate.opsForValue().setIfAbsent(key, value);
-    }
-
-    /**
-     * 分布式锁
-     *
-     * @param key
-     * @param value
-     * @return
-     */
-    public boolean setNx(final String key, String value, final Long timeout, final TimeUnit timeUnit) {
-        return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
-    }
-
-    /**
-     * 缓存基本的对象,Integer、String、实体类等
-     *
-     * @param key      缓存的键值
-     * @param value    缓存的值
-     * @param timeout  时间
-     * @param timeUnit 时间颗粒度
-     */
-    public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
-        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
-    }
-
-    /**
-     * 设置有效时间
-     *
-     * @param key Redis键
-     * @param timeout 超时时间
-     * @return true=设置成功;false=设置失败
-     */
-    public boolean expire(final String key, final long timeout)
-    {
-        return expire(key, timeout, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 设置有效时间
-     *
-     * @param key Redis键
-     * @param timeout 超时时间
-     * @param unit 时间单位
-     * @return true=设置成功;false=设置失败
-     */
-    public boolean expire(final String key, final long timeout, final TimeUnit unit)
-    {
-        return redisTemplate.expire(key, timeout, unit);
-    }
-
-    /**
-     * 获取有效时间
-     *
-     * @param key Redis键
-     * @return 有效时间
-     */
-    public long getExpire(final String key)
-    {
-        return redisTemplate.getExpire(key);
-    }
-
-    /**
-     * 判断 key是否存在
-     *
-     * @param key 键
-     * @return true 存在 false不存在
-     */
-    public Boolean hasKey(String key)
-    {
-        return redisTemplate.hasKey(key);
-    }
-
-    /**
-     * 获得缓存的基本对象。
-     *
-     * @param key 缓存键值
-     * @return 缓存键值对应的数据
-     */
-    public <T> T getCacheObject(final String key)
-    {
-        ValueOperations<String, T> operation = redisTemplate.opsForValue();
-        return operation.get(key);
-    }
-
-    /**
-     * 获得缓存的基本对象。
-     *
-     * @param key 缓存键值
-     * @return 缓存键值对应的数据
-     */
-    public Long increment(final String key) {
-        return redisTemplate.opsForValue().increment(key);
-    }
-
-    public Long incrementMap(String key, String filed) {
-        return redisTemplate.opsForHash().increment(key, filed, 1L);
-    }
-
-    /**
-     * 删除单个对象
-     *
-     * @param key
-     */
-    public boolean deleteObject(final String key) {
-        return redisTemplate.delete(key);
-    }
-
-    /**
-     * 删除集合对象
-     *
-     * @param collection 多个对象
-     * @return
-     */
-    public boolean deleteObject(final Collection collection)
-    {
-        return redisTemplate.delete(collection) > 0;
-    }
-
-    /**
-     * 缓存List数据
-     *
-     * @param key 缓存的键值
-     * @param dataList 待缓存的List数据
-     * @return 缓存的对象
-     */
-    public <T> long setCacheList(final String key, final List<T> dataList)
-    {
-        Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
-        return count == null ? 0 : count;
-    }
-    /**
-     * 获得缓存的基本对象列表
-     *
-     * @param pattern 字符串前缀
-     * @return 对象列表
-     */
-    public Collection<String> keys(final String pattern)
-    {
-        return redisTemplate.keys(pattern);
-    }
-    /**
-     * 获得缓存的list对象
-     *
-     * @param key 缓存的键值
-     * @return 缓存键值对应的数据
-     */
-    public <T> List<T> getCacheList(final String key)
-    {
-        return redisTemplate.opsForList().range(key, 0, -1);
-    }
-
-    /**
-     * 缓存Set
-     *
-     * @param key 缓存键值
-     * @param dataSet 缓存的数据
-     * @return 缓存数据的对象
-     */
-    public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
-    {
-        BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
-        Iterator<T> it = dataSet.iterator();
-        while (it.hasNext())
-        {
-            setOperation.add(it.next());
-        }
-        return setOperation;
-    }
-
-    /**
-     * 获得缓存的set
-     *
-     * @param key
-     * @return
-     */
-    public <T> Set<T> getCacheSet(final String key)
-    {
-        return redisTemplate.opsForSet().members(key);
-    }
-
-    /**
-     * 添加元素缓存的set
-     * @param key
-     * @param values
-     * @return
-     * @param <T>
-     */
-    public <T> Long addCacheSet(final String key, final T... values)
-    {
-        return redisTemplate.opsForSet().add(key, values);
-    }
-
-    /**
-     * 删除缓存set的元素
-     * @param key
-     * @param values
-     * @return
-     * @param <T>
-     */
-    public <T> Long removeCacheSet(final String key, final T... values)
-    {
-        return redisTemplate.opsForSet().remove(key, values);
-    }
-
-    /**
-     * 缓存的set的size
-     * @param key
-     * @return
-     * @param <T>
-     */
-    public <T> Long size(final String key)
-    {
-        return redisTemplate.opsForSet().size(key);
-    }
-
-    /**
-     * set是否包含value
-     * @param key
-     * @param object
-     * @return
-     */
-    public Boolean isMember(final String key, final Object object)
-    {
-        return redisTemplate.opsForSet().isMember(key, object);
-    }
-
-    /**
-     * 缓存Map
-     *
-     * @param key
-     * @param dataMap
-     */
-    public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
-    {
-        if (dataMap != null) {
-            redisTemplate.opsForHash().putAll(key, dataMap);
-        }
-    }
-
-    /**
-     * 获得缓存的Map
-     *
-     * @param key
-     * @return
-     */
-    public <T> Map<String, T> getCacheMap(final String key)
-    {
-        return redisTemplate.opsForHash().entries(key);
-    }
-
-    /**
-     * 往Hash中存入数据
-     *
-     * @param key Redis键
-     * @param hKey Hash键
-     * @param value 值
-     */
-    public <T> void setCacheMapValue(final String key, final String hKey, final T value)
-    {
-        redisTemplate.opsForHash().put(key, hKey, value);
-    }
-
-    /**
-     * 获取Hash中的数据
-     *
-     * @param key Redis键
-     * @param hKey Hash键
-     * @return Hash中的对象
-     */
-    public <T> T getCacheMapValue(final String key, final String hKey)
-    {
-        HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
-        return opsForHash.get(key, hKey);
-    }
-
-
-    /**
-     * 获取多个Hash中的数据
-     *
-     * @param key Redis键
-     * @param hKeys Hash键集合
-     * @return Hash对象集合
-     */
-    public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
-    {
-        return redisTemplate.opsForHash().multiGet(key, hKeys);
-    }
-
-    /**
-     * 删除Hash中的某条数据
-     *
-     * @param key  Redis键
-     * @param hKey Hash键
-     * @return 是否成功
-     */
-    public boolean deleteCacheMapValue(final String key, final String hKey) {
-        return redisTemplate.opsForHash().delete(key, hKey) > 0;
-    }
-
-    @Override
-    public void run(String... args) throws Exception {
-        redisTemplate.opsForValue().set("test", RandomUtil.randomString(2));
-    }
-
-    /**
-     * 获得缓存的基本对象列表
-     *
-     * @param pattern 字符串前缀
-     * @return 对象列表
-     */
-}
+//package cn.hfln.framework.gateway.config;
+//
+//import cn.hutool.core.util.RandomUtil;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.boot.CommandLineRunner;
+//import org.springframework.data.redis.core.BoundSetOperations;
+//import org.springframework.data.redis.core.HashOperations;
+//import org.springframework.data.redis.core.RedisTemplate;
+//import org.springframework.data.redis.core.ValueOperations;
+//import org.springframework.stereotype.Component;
+//
+//import java.util.*;
+//import java.util.concurrent.TimeUnit;
+//
+///**
+// * spring redis 工具类
+// *
+// * @author cw
+// **/
+//@SuppressWarnings(value = {"unchecked", "rawtypes"})
+//@Component
+//public class RedisService implements CommandLineRunner {
+//    @Autowired
+//    public RedisTemplate redisTemplate;
+//
+//    /**
+//     * 缓存基本的对象,Integer、String、实体类等
+//     *
+//     * @param key   缓存的键值
+//     * @param value 缓存的值
+//     */
+//    public <T> void setCacheObject(final String key, final T value) {
+//        redisTemplate.opsForValue().set(key, value);
+//    }
+//
+//    /**
+//     * 分布式锁
+//     *
+//     * @param key
+//     * @param value
+//     * @return
+//     */
+//    public boolean setNx(final String key, String value) {
+//        return redisTemplate.opsForValue().setIfAbsent(key, value);
+//    }
+//
+//    /**
+//     * 分布式锁
+//     *
+//     * @param key
+//     * @param value
+//     * @return
+//     */
+//    public boolean setNx(final String key, String value, final Long timeout, final TimeUnit timeUnit) {
+//        return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
+//    }
+//
+//    /**
+//     * 缓存基本的对象,Integer、String、实体类等
+//     *
+//     * @param key      缓存的键值
+//     * @param value    缓存的值
+//     * @param timeout  时间
+//     * @param timeUnit 时间颗粒度
+//     */
+//    public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
+//        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
+//    }
+//
+//    /**
+//     * 设置有效时间
+//     *
+//     * @param key Redis键
+//     * @param timeout 超时时间
+//     * @return true=设置成功;false=设置失败
+//     */
+//    public boolean expire(final String key, final long timeout)
+//    {
+//        return expire(key, timeout, TimeUnit.SECONDS);
+//    }
+//
+//    /**
+//     * 设置有效时间
+//     *
+//     * @param key Redis键
+//     * @param timeout 超时时间
+//     * @param unit 时间单位
+//     * @return true=设置成功;false=设置失败
+//     */
+//    public boolean expire(final String key, final long timeout, final TimeUnit unit)
+//    {
+//        return redisTemplate.expire(key, timeout, unit);
+//    }
+//
+//    /**
+//     * 获取有效时间
+//     *
+//     * @param key Redis键
+//     * @return 有效时间
+//     */
+//    public long getExpire(final String key)
+//    {
+//        return redisTemplate.getExpire(key);
+//    }
+//
+//    /**
+//     * 判断 key是否存在
+//     *
+//     * @param key 键
+//     * @return true 存在 false不存在
+//     */
+//    public Boolean hasKey(String key)
+//    {
+//        return redisTemplate.hasKey(key);
+//    }
+//
+//    /**
+//     * 获得缓存的基本对象。
+//     *
+//     * @param key 缓存键值
+//     * @return 缓存键值对应的数据
+//     */
+//    public <T> T getCacheObject(final String key)
+//    {
+//        ValueOperations<String, T> operation = redisTemplate.opsForValue();
+//        return operation.get(key);
+//    }
+//
+//    /**
+//     * 获得缓存的基本对象。
+//     *
+//     * @param key 缓存键值
+//     * @return 缓存键值对应的数据
+//     */
+//    public Long increment(final String key) {
+//        return redisTemplate.opsForValue().increment(key);
+//    }
+//
+//    public Long incrementMap(String key, String filed) {
+//        return redisTemplate.opsForHash().increment(key, filed, 1L);
+//    }
+//
+//    /**
+//     * 删除单个对象
+//     *
+//     * @param key
+//     */
+//    public boolean deleteObject(final String key) {
+//        return redisTemplate.delete(key);
+//    }
+//
+//    /**
+//     * 删除集合对象
+//     *
+//     * @param collection 多个对象
+//     * @return
+//     */
+//    public boolean deleteObject(final Collection collection)
+//    {
+//        return redisTemplate.delete(collection) > 0;
+//    }
+//
+//    /**
+//     * 缓存List数据
+//     *
+//     * @param key 缓存的键值
+//     * @param dataList 待缓存的List数据
+//     * @return 缓存的对象
+//     */
+//    public <T> long setCacheList(final String key, final List<T> dataList)
+//    {
+//        Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
+//        return count == null ? 0 : count;
+//    }
+//    /**
+//     * 获得缓存的基本对象列表
+//     *
+//     * @param pattern 字符串前缀
+//     * @return 对象列表
+//     */
+//    public Collection<String> keys(final String pattern)
+//    {
+//        return redisTemplate.keys(pattern);
+//    }
+//    /**
+//     * 获得缓存的list对象
+//     *
+//     * @param key 缓存的键值
+//     * @return 缓存键值对应的数据
+//     */
+//    public <T> List<T> getCacheList(final String key)
+//    {
+//        return redisTemplate.opsForList().range(key, 0, -1);
+//    }
+//
+//    /**
+//     * 缓存Set
+//     *
+//     * @param key 缓存键值
+//     * @param dataSet 缓存的数据
+//     * @return 缓存数据的对象
+//     */
+//    public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
+//    {
+//        BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
+//        Iterator<T> it = dataSet.iterator();
+//        while (it.hasNext())
+//        {
+//            setOperation.add(it.next());
+//        }
+//        return setOperation;
+//    }
+//
+//    /**
+//     * 获得缓存的set
+//     *
+//     * @param key
+//     * @return
+//     */
+//    public <T> Set<T> getCacheSet(final String key)
+//    {
+//        return redisTemplate.opsForSet().members(key);
+//    }
+//
+//    /**
+//     * 添加元素缓存的set
+//     * @param key
+//     * @param values
+//     * @return
+//     * @param <T>
+//     */
+//    public <T> Long addCacheSet(final String key, final T... values)
+//    {
+//        return redisTemplate.opsForSet().add(key, values);
+//    }
+//
+//    /**
+//     * 删除缓存set的元素
+//     * @param key
+//     * @param values
+//     * @return
+//     * @param <T>
+//     */
+//    public <T> Long removeCacheSet(final String key, final T... values)
+//    {
+//        return redisTemplate.opsForSet().remove(key, values);
+//    }
+//
+//    /**
+//     * 缓存的set的size
+//     * @param key
+//     * @return
+//     * @param <T>
+//     */
+//    public <T> Long size(final String key)
+//    {
+//        return redisTemplate.opsForSet().size(key);
+//    }
+//
+//    /**
+//     * set是否包含value
+//     * @param key
+//     * @param object
+//     * @return
+//     */
+//    public Boolean isMember(final String key, final Object object)
+//    {
+//        return redisTemplate.opsForSet().isMember(key, object);
+//    }
+//
+//    /**
+//     * 缓存Map
+//     *
+//     * @param key
+//     * @param dataMap
+//     */
+//    public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
+//    {
+//        if (dataMap != null) {
+//            redisTemplate.opsForHash().putAll(key, dataMap);
+//        }
+//    }
+//
+//    /**
+//     * 获得缓存的Map
+//     *
+//     * @param key
+//     * @return
+//     */
+//    public <T> Map<String, T> getCacheMap(final String key)
+//    {
+//        return redisTemplate.opsForHash().entries(key);
+//    }
+//
+//    /**
+//     * 往Hash中存入数据
+//     *
+//     * @param key Redis键
+//     * @param hKey Hash键
+//     * @param value 值
+//     */
+//    public <T> void setCacheMapValue(final String key, final String hKey, final T value)
+//    {
+//        redisTemplate.opsForHash().put(key, hKey, value);
+//    }
+//
+//    /**
+//     * 获取Hash中的数据
+//     *
+//     * @param key Redis键
+//     * @param hKey Hash键
+//     * @return Hash中的对象
+//     */
+//    public <T> T getCacheMapValue(final String key, final String hKey)
+//    {
+//        HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
+//        return opsForHash.get(key, hKey);
+//    }
+//
+//
+//    /**
+//     * 获取多个Hash中的数据
+//     *
+//     * @param key Redis键
+//     * @param hKeys Hash键集合
+//     * @return Hash对象集合
+//     */
+//    public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
+//    {
+//        return redisTemplate.opsForHash().multiGet(key, hKeys);
+//    }
+//
+//    /**
+//     * 删除Hash中的某条数据
+//     *
+//     * @param key  Redis键
+//     * @param hKey Hash键
+//     * @return 是否成功
+//     */
+//    public boolean deleteCacheMapValue(final String key, final String hKey) {
+//        return redisTemplate.opsForHash().delete(key, hKey) > 0;
+//    }
+//
+//    @Override
+//    public void run(String... args) throws Exception {
+//        redisTemplate.opsForValue().set("test", RandomUtil.randomString(2));
+//    }
+//
+//    /**
+//     * 获得缓存的基本对象列表
+//     *
+//     * @param pattern 字符串前缀
+//     * @return 对象列表
+//     */
+//}

+ 4 - 3
src/main/java/cn/hfln/framework/gateway/config/StpInterfaceImpl.java

@@ -3,6 +3,7 @@ package cn.hfln.framework.gateway.config;
 import cn.dev33.satoken.stp.StpInterface;
 
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hfln.framework.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -25,7 +26,7 @@ public class StpInterfaceImpl implements StpInterface {
 
 
 	@Autowired
-	private RedisService redisService;
+	private RedisUtil redisService;
 	/**
 	 * 返回一个账号所拥有的权限码集合
 	 */
@@ -39,7 +40,7 @@ public class StpInterfaceImpl implements StpInterface {
 		List<String> roleList = this.getRoleList(loginId, loginType);
 		for (String roleId : roleList) {
 			String rolePermKeyPre = "hfln:perm:";
-			Set<String> permList = redisService.getCacheSet(rolePermKeyPre + roleId);
+			Set<String> permList = (Set<String>) redisService.get(rolePermKeyPre + roleId);
 			if (permList == null) {
 				log.error("角色权限列表不存在, roleId :{}", roleId);
 				throw new RuntimeException(roleId + "角色权限列表不存在");
@@ -58,7 +59,7 @@ public class StpInterfaceImpl implements StpInterface {
 		long loginId = Long.parseLong(String.valueOf(loginIdObj));
 		// 当前登录用户的角色
 		String roleKeyPre = "hfln:role:";
-		Set<String> roleList = redisService.getCacheSet(roleKeyPre + loginId);
+		Set<String> roleList = (Set<String>) redisService.get(roleKeyPre + loginId);
 		if (CollectionUtils.isEmpty(roleList)) {
 			log.error("角色配置异常, loginId :{}", loginId);
 			throw new RuntimeException("角色配置异常");