Skip to content

Commit

Permalink
feat: support the config of "spring-redis"
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Jun 12, 2024
1 parent e096598 commit a028ee9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
4 changes: 2 additions & 2 deletions arex-schedule-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<parent>
<artifactId>arex-schedule-parent</artifactId>
<groupId>com.arextest</groupId>
<version>1.1.32</version>
<version>1.2.0</version>
</parent>

<profiles>
Expand Down Expand Up @@ -338,5 +338,5 @@
</properties>
</profile>
</profiles>
<version>1.1.32</version>
<version>1.2.0</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,65 @@
import com.arextest.common.cache.CacheProvider;
import com.arextest.common.cache.DefaultRedisCacheProvider;
import com.arextest.common.cache.SentinelRedisCacheProvider;
import com.arextest.common.cache.redistemplate.RedisTemplateCacheProvider;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
* @author jmo
* @since 2021/10/18
*/
@Configuration
@ConditionalOnMissingBean(CacheProvider.class)
@SuppressWarnings("java:S6857")
class CacheProviderConfiguration {

@Value("${arex.redis.uri}")
private String scheduleCacheRedisHost;
@Value("${arex.redis.uri:}")
private String redisUri;

@Value("${arex.redis.sentinelUrl:}")
private String sentinelUrl;

@Bean
CacheProvider cacheProvider() {
@ConditionalOnMissingBean(CacheProvider.class)
@ConditionalOnExpression("!'${arex.redis.uri:}'.isEmpty() or !'${arex.redis.sentinelUrl:}'.isEmpty()")
public CacheProvider cacheProvider() {
if (StringUtils.isNotEmpty(sentinelUrl)) {
return new SentinelRedisCacheProvider(sentinelUrl);
}
return new DefaultRedisCacheProvider(scheduleCacheRedisHost);
return new DefaultRedisCacheProvider(redisUri);
}

@Bean
@ConditionalOnExpression("!'${arex.redis.uri:}'.isEmpty() or !'${arex.redis.sentinelUrl:}'.isEmpty()")
public RedissonClient redissonClient(CacheProvider cacheProvider) {
return cacheProvider.getRedissionClient();
}

@Bean
@ConditionalOnExpression("'${arex.redis.uri:}'.isEmpty() and '${arex.redis.sentinelUrl:}'.isEmpty()")
public RedisTemplate<byte[], byte[]> redisTemplate(
RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(RedisSerializer.byteArray());
template.setValueSerializer(RedisSerializer.byteArray());
return template;
}


@Bean
@ConditionalOnExpression("'${arex.redis.uri:}'.isEmpty() and '${arex.redis.sentinelUrl:}'.isEmpty()")
@ConditionalOnMissingBean(CacheProvider.class)
public CacheProvider redisCacheProvider(RedisTemplate redisTemplate,
RedissonClient redissonClient) {
return new RedisTemplateCacheProvider(redisTemplate, redissonClient);
}
}
15 changes: 9 additions & 6 deletions arex-schedule-web-api/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ logging:
arex:
api:
service:
api: http://10.144.62.53:8090
api: http://10.118.1.217:18090
mongo:
uri: mongodb://arex:[email protected]:27017/arex_storage_db
redis:
uri: redis://10.144.62.53:6379
uri: mongodb://arex:[email protected]:37017/arex_storage_db
storage:
service:
api: http://10.144.62.53:8093
api: http://10.118.1.217:18093
schedule:
service:
api: http://10.144.62.53:8092
api: http://10.118.1.217:18092

spring:
redis:
host: 10.118.1.217
port: 16379
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ arex:
api: http://arex-report-service:8080
mongo:
uri: mongodb://arex:password@mongodb:27017/arex_storage_db
redis:
uri: redis://redis:6379
storage:
service:
api: http://arex-storage-service:8080
schedule:
service:
api: http://arex-schedule-service:8080
api: http://arex-schedule-service:8080
spring:
redis:
host: redis
port: 6379
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@
<groupId>com.alibaba.fastjson2</groupId>
<version>${fastjson2.version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<description>AREX schedule is used for replay.</description>
Expand Down Expand Up @@ -304,7 +309,8 @@
</sonar.exclusions>
<arex-storage-config.version>1.1.36</arex-storage-config.version>
<web-contract.version>0.6.4.9</web-contract.version>
<arex-common.version>0.1.26</arex-common.version>
<arex-common.version>0.1.28</arex-common.version>
<redisson.version>3.20.1</redisson.version>
</properties>

<scm>
Expand All @@ -314,5 +320,5 @@
<url>https://github.com/arextest/arex-replay-schedule</url>
</scm>
<url>https://github.com/arextest/arex-replay-schedule</url>
<version>1.1.32</version>
<version>1.2.0</version>
</project>

0 comments on commit a028ee9

Please sign in to comment.