Skip to content

Commit

Permalink
[#9666] Fixed redis properties
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed May 22, 2023
1 parent 9e0ef71 commit b1572be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private Consumer<Long> makeTickHandler(SessionContext ctx, WebSocketSession sess
final List<ClusterKey> agentKeys =
this.agentLookupService.getRecentAgents(applicationName, TimeUnit.HOURS.toMillis(1));
final TickHandler handler = new TickHandler(session, applicationName, agentKeys, getFetchers(agentKeys));

return ignoreArgument(decorateHandler(ctx.getTaskDecorator(), handler));
final Runnable decoratedHandler = decorateHandler(ctx.getTaskDecorator(), handler);
return t -> decoratedHandler.run();
}

private List<Fetcher<ATCSupply>> getFetchers(List<ClusterKey> agentKeys) {
Expand Down Expand Up @@ -157,10 +157,6 @@ private static Runnable decorateHandler(TimerTaskDecorator decorator, TimerTask
return decorator.decorate(target);
}

private static <T> Consumer<T> ignoreArgument(Runnable r) {
return t -> r.run();
}

private class TickHandler extends TimerTask {

private final WebSocketSession session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import io.lettuce.core.TimeoutOptions;
import io.lettuce.core.resource.ClientResources;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand Down Expand Up @@ -60,7 +58,7 @@ public class RedisBasicConfig {
@Value("${spring.data.redis.port:6379}")
int port;

@Value("${spring.data.redis.cluster.nodes:@null}")
@Value("${spring.data.redis.cluster.nodes}")
List<String> clusterNodes;
@Value("${spring.data.redis.lettuce.client.io-thread-pool-size:8}")
int lettuceIOThreadPoolSize;
Expand All @@ -86,22 +84,17 @@ ReactiveRedisTemplate<String, String> reactiveRedisTemplate(ReactiveRedisConnect
}

@Bean
@ConditionalOnProperty("spring.redis.cluster.nodes")
RedisConfiguration redisClusterConfiguration() {
Assert.notNull(clusterNodes, "clusterNodes are required for redis-cluster mode");
RedisConfiguration redisConfiguration() {
if (clusterNodes == null || clusterNodes.isEmpty()) {
Assert.hasText(host, "host is required for redis-standalone mode");

final RedisClusterConfiguration config = new RedisClusterConfiguration(clusterNodes);
config.setUsername(username);
config.setPassword(password);
return config;
}

@Bean
@ConditionalOnMissingBean(RedisConfiguration.class)
RedisConfiguration redisStandaloneConfiguration() {
Assert.hasText(host, "host is required for redis-standalone mode");
final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
config.setUsername(username);
config.setPassword(password);
return config;
}

final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
final RedisClusterConfiguration config = new RedisClusterConfiguration(clusterNodes);
config.setUsername(username);
config.setPassword(password);
return config;
Expand Down

0 comments on commit b1572be

Please sign in to comment.