Skip to content

Commit

Permalink
refactor: 适配 ContiNew Starter Redisson 自动配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 22, 2023
1 parent f4c0919 commit a40e609
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 281 deletions.
14 changes: 7 additions & 7 deletions continew-admin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
<artifactId>continew-starter-api-doc</artifactId>
</dependency>

<!-- ContiNew Starter Jackson 依赖 -->
<!-- ContiNew Starter Redisson 依赖(Redis 缓存) -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-cache-redisson</artifactId>
</dependency>

<!-- ContiNew Starter Jackson 依赖(JSON) -->
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-json-jackson</artifactId>
Expand Down Expand Up @@ -114,12 +120,6 @@
<artifactId>mica-ip2region</artifactId>
</dependency>

<!-- Redisson(不仅仅是一个 Redis Java 客户端) -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
</dependency>

<!-- Easy Captcha(Java 图形验证码,支持 gif、中文、算术等类型,可用于 Java Web、JavaSE 等项目) -->
<dependency>
<groupId>com.github.whvcse</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.redisson.codec.JsonJacksonCodec;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
Expand All @@ -41,7 +39,7 @@
import cn.hutool.json.JSONUtil;

/**
* Redis 配置
* Spring Cache 配置
*
* @author Charles7c
* @since 2022/12/28 23:17
Expand All @@ -50,19 +48,10 @@
@EnableCaching
@Configuration
@RequiredArgsConstructor
public class RedisConfiguration extends CachingConfigurerSupport {
public class SpringCacheConfiguration extends CachingConfigurerSupport {

private final ObjectMapper objectMapper;

/**
* Redisson 自定义配置
*/
@Bean
public RedissonAutoConfigurationCustomizer redissonCustomizer() {
// 解决序列化乱码问题
return config -> config.setCodec(new JsonJacksonCodec(objectMapper));
}

/**
* 解决 Spring Cache(@Cacheable)缓存乱码问题
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.time.Duration;

import top.charles7c.cnadmin.common.constant.CacheConsts;
import top.charles7c.cnadmin.common.util.RedisUtils;
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;

import me.zhyd.oauth.cache.AuthStateCache;

Expand All @@ -42,7 +42,7 @@ public class JustAuthRedisStateCache implements AuthStateCache {
@Override
public void cache(String key, String value) {
// 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟
RedisUtils.setCacheObject(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
RedisUtils.set(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
Duration.ofMinutes(3));
}

Expand All @@ -58,7 +58,7 @@ public void cache(String key, String value) {
*/
@Override
public void cache(String key, String value, long timeout) {
RedisUtils.setCacheObject(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
RedisUtils.set(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
Duration.ofMillis(timeout));
}

Expand All @@ -71,7 +71,7 @@ public void cache(String key, String value, long timeout) {
*/
@Override
public String get(String key) {
return RedisUtils.getCacheObject(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
return RedisUtils.get(RedisUtils.formatKey(CacheConsts.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.util.SaFoxUtil;

import top.charles7c.cnadmin.common.util.RedisUtils;
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;

/**
* Sa-Token 持久层本地 Redis 适配(参考:Sa-Token/sa-token-plugin/sa-token-dao-redisx/SaTokenDaoOfRedis.java)
Expand All @@ -37,7 +37,7 @@ public class SaTokenRedisDaoImpl implements SaTokenDao {

@Override
public String get(String key) {
return RedisUtils.getCacheObject(key);
return RedisUtils.get(key);
}

@Override
Expand All @@ -47,9 +47,9 @@ public void set(String key, String value, long timeout) {
}
// 判断是否为永不过期
if (timeout == SaTokenDao.NEVER_EXPIRE) {
RedisUtils.setCacheObject(key, value);
RedisUtils.set(key, value);
} else {
RedisUtils.setCacheObject(key, value, Duration.ofSeconds(timeout));
RedisUtils.set(key, value, Duration.ofSeconds(timeout));
}
}

Expand All @@ -65,7 +65,7 @@ public void update(String key, String value) {

@Override
public void delete(String key) {
RedisUtils.deleteCacheObject(key);
RedisUtils.delete(key);
}

@Override
Expand All @@ -92,7 +92,7 @@ public void updateTimeout(String key, long timeout) {

@Override
public Object getObject(String key) {
return RedisUtils.getCacheObject(key);
return RedisUtils.get(key);
}

@Override
Expand All @@ -102,9 +102,9 @@ public void setObject(String key, Object object, long timeout) {
}
// 判断是否为永不过期
if (timeout == SaTokenDao.NEVER_EXPIRE) {
RedisUtils.setCacheObject(key, object);
RedisUtils.set(key, object);
} else {
RedisUtils.setCacheObject(key, object, Duration.ofSeconds(timeout));
RedisUtils.set(key, object, Duration.ofSeconds(timeout));
}
}

Expand All @@ -120,7 +120,7 @@ public void updateObject(String key, Object object) {

@Override
public void deleteObject(String key) {
RedisUtils.deleteCacheObject(key);
RedisUtils.delete(key);
}

@Override
Expand Down
Loading

0 comments on commit a40e609

Please sign in to comment.