refactor: 重构 sa-token-alone-redis 插件

This commit is contained in:
click33 2025-02-22 16:58:34 +08:00
parent 935a8db3ae
commit 5dbaab1966
4 changed files with 18 additions and 49 deletions

View File

@ -25,11 +25,11 @@
<module>sa-token-fastjson</module>
<module>sa-token-fastjson2</module>
<module>sa-token-hutool-timed-cache</module>
<module>sa-token-alone-redis</module>
<module>sa-token-redisson-jackson</module>
<module>sa-token-redisson-jackson2</module>
<module>sa-token-redisx</module>
<module>sa-token-alone-redis</module>
<module>sa-token-dialect-thymeleaf</module>
<module>sa-token-freemarker</module>
<module>sa-token-sso</module>

View File

@ -24,20 +24,10 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-jackson</artifactId>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-template-jdk-serializer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-fastjson</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-fastjson2</artifactId>
<optional>true</optional>
</dependency>
</dependency>
<!-- redis pool -->
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -17,9 +17,8 @@ package cn.dev33.satoken.dao.alone;
import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.dao.SaTokenDaoDefaultImpl;
import cn.dev33.satoken.dao.SaTokenDaoRedisFastjson;
import cn.dev33.satoken.dao.SaTokenDaoRedisFastjson2;
import cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate;
import cn.dev33.satoken.dao.SaTokenDaoForRedisTemplateUseJdkSerializer;
import cn.dev33.satoken.exception.SaTokenException;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
@ -44,10 +43,8 @@ import java.util.stream.Collectors;
* <p>
* 使用方式在引入 sa-token redis 集成相关包的前提下继续引入当前依赖 <br> <br>
* 注意事项目前本依赖仅对以下插件有 Redis 分离效果 <br>
* sa-token-redis <br>
* sa-token-redis-jackson <br>
* sa-token-redis-fastjson <br>
* sa-token-redis-fastjson2 <br>
* sa-token-redis-template <br>
* sa-token-redis-template-jdk-serializer <br>
* </p>
*
*
@ -212,7 +209,16 @@ public class SaAloneRedisInject implements EnvironmentAware{
// 3. 开始初始化 SaTokenDao 此处需要依次判断开发者引入的是哪个 redis
// 如果开发者引入的是sa-token-redis
// 如果开发者引入的是sa-token-redis-template-jdk-serializer
try {
Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplateUseJdkSerializer");
SaTokenDaoForRedisTemplateUseJdkSerializer dao = (SaTokenDaoForRedisTemplateUseJdkSerializer)saTokenDao;
dao.isInit = false;
dao.init(factory);
return;
} catch (ClassNotFoundException ignored) {
}
// 如果开发者引入的是sa-token-redis-template
try {
Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate");
SaTokenDaoForRedisTemplate dao = (SaTokenDaoForRedisTemplate)saTokenDao;
@ -221,33 +227,6 @@ public class SaAloneRedisInject implements EnvironmentAware{
return;
} catch (ClassNotFoundException ignored) {
}
// TODO: 如果开发者引入的是sa-token-redis-jdk-serializer
// try {
// Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate");
// SaTokenDaoRedisJackson dao = (SaTokenDaoRedisJackson)saTokenDao;
// dao.isInit = false;
// dao.init(factory);
// return;
// } catch (ClassNotFoundException ignored) {
// }
// 如果开发者引入的是sa-token-redis-fastjson
try {
Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisFastjson");
SaTokenDaoRedisFastjson dao = (SaTokenDaoRedisFastjson)saTokenDao;
dao.isInit = false;
dao.init(factory);
return;
} catch (ClassNotFoundException ignored) {
}
// 如果开发者引入的是sa-token-redis-fastjson2
try {
Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisFastjson2");
SaTokenDaoRedisFastjson2 dao = (SaTokenDaoRedisFastjson2)saTokenDao;
dao.isInit = false;
dao.init(factory);
return;
} catch (ClassNotFoundException ignored) {
}
// 至此说明开发者一个 redis 插件也没引入或者引入的 redis 插件不在 sa-token-alone-redis 的支持范围内

View File

@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
/**
* Sa-Token 持久层实现 [ RedisTemplate 存储 ] (可用环境: SpringBoot2SpringBoot3)
* <br> copy by: sa-token-redis-template 插件
* <br> copy by: sa-token-redis-template 插件
*
* @author click33
* @since 1.34.0