From 5e5099f457e1688612449bfe8910a4e524743be6 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 4 Jun 2021 11:34:30 +0800 Subject: [PATCH] - add support MasterReplica MODE - optimize connection utilization - fix missing digest method when using the lower version of the lettuce client. --- README.md | 32 +++--- README.zh-CN.md | 32 +++--- .../ahoo/cosky/config/ConfigKeyGenerator.java | 2 +- .../config/redis/ConfigRedisScripts.java | 2 +- .../config/redis/BaseOnRedisClientTest.java | 2 +- .../RedisClusterMessageListenable.java | 12 +-- .../cosky/core/{ => redis}/RedisConfig.java | 24 ++++- .../cosky/core/redis/RedisConnection.java | 31 ++++++ .../core/redis/RedisConnectionFactory.java | 98 +++++++++++++++++++ .../core/redis/RedisScriptInitializer.java | 24 ++--- .../core/{util => redis}/RedisScripts.java | 5 +- .../me/ahoo/cosky/core/util/ScriptTest.java | 1 - .../redis/DiscoveryRedisScripts.java | 2 +- .../discovery/BaseOnRedisClientTest.java | 2 +- .../cosky/rest/controller/StatController.java | 2 - .../spring/cloud/CoskyAutoConfiguration.java | 37 ++++--- .../cosky/spring/cloud/CoskyProperties.java | 2 +- .../cloud/support/RedisClientSupport.java | 40 -------- gradle.properties | 2 +- k8s/deployment/cosky-mirror.yml | 2 +- k8s/deployment/cosky-rest-api.yml | 2 +- k8s/docker/cosky-mirror/Dockerfile | 6 +- k8s/docker/rest-api-local/Dockerfile | 6 +- k8s/docker/rest-api/Dockerfile | 6 +- .../cloud/CoskyConfigAutoConfiguration.java | 4 +- .../CoskyConfigBootstrapConfiguration.java | 7 +- .../cloud/CoskyPropertySourceLocator.java | 4 +- .../cloud/refresh/CoskyConfigRefresher.java | 4 +- .../CoskyDiscoveryAutoConfiguration.java | 11 +-- ...oServiceRegistrationAutoConfiguration.java | 7 +- 30 files changed, 259 insertions(+), 152 deletions(-) rename cosky-core/src/main/java/me/ahoo/cosky/core/{ => redis}/RedisConfig.java (50%) create mode 100644 cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnection.java create mode 100644 cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnectionFactory.java rename cosky-core/src/main/java/me/ahoo/cosky/core/{util => redis}/RedisScripts.java (96%) delete mode 100644 cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/support/RedisClientSupport.java diff --git a/README.md b/README.md index e5e94c51..125bf37a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ between process cache and Redis. > Kotlin DSL ``` kotlin - val coskyVersion = "1.1.3"; + val coskyVersion = "1.1.5"; implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}") implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}") ``` @@ -52,7 +52,7 @@ between process cache and Redis. 4.0.0 demo - 1.1.3 + 1.1.5 @@ -96,30 +96,30 @@ logging: #### Option 1:Download the executable file -> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.3/cosky-rest-api-1.1.3.tar) +> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.5/cosky-rest-api-1.1.5.tar) -> tar *cosky-rest-api-1.1.3.tar* +> tar *cosky-rest-api-1.1.5.tar* ```shell -cd cosky-rest-api-1.1.3 -# Working directory: cosky-rest-api-1.1.3 +cd cosky-rest-api-1.1.5 +# Working directory: cosky-rest-api-1.1.5 bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379 ``` #### Option 2:Run On Docker ```shell -docker pull ahoowang/cosky-rest-api:1.1.3 -docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3 +docker pull ahoowang/cosky-rest-api:1.1.5 +docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.5 ``` ##### MacBook Pro (M1) -> Please use *ahoowang/cosky-rest-api:1.1.3-armv7* +> Please use *ahoowang/cosky-rest-api:1.1.5-armv7* ```shell -docker pull ahoowang/cosky-rest-api:1.1.3-armv7 -docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3-armv7 +docker pull ahoowang/cosky-rest-api:1.1.5-armv7 +docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.5-armv7 ``` #### Option 3:Run On Kubernetes @@ -147,7 +147,7 @@ spec: value: standalone - name: COSKY_REDIS_URI value: redis://redis-uri:6379 - image: ahoowang/cosky-rest-api:1.1.3 + image: ahoowang/cosky-rest-api:1.1.5 name: cosky-rest-api ports: - containerPort: 8080 @@ -281,12 +281,12 @@ spec: ``` shell gradle cosky-config:jmh # or -java -jar cosky-config/build/libs/cosky-config-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 +java -jar cosky-config/build/libs/cosky-config-1.1.5-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 ``` ``` # JMH version: 1.29 -# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS +# VM version: JDK 11.1.51, OpenJDK 64-Bit Server VM, 11.1.51+9-LTS # VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java # VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant # Blackhole mode: full + dont-inline hint @@ -307,12 +307,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132 ``` shell gradle cosky-discovery:jmh # or -java -jar cosky-discovery/build/libs/cosky-discovery-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 +java -jar cosky-discovery/build/libs/cosky-discovery-1.1.5-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 ``` ``` # JMH version: 1.29 -# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS +# VM version: JDK 11.1.51, OpenJDK 64-Bit Server VM, 11.1.51+9-LTS # VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java # VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant # Blackhole mode: full + dont-inline hint diff --git a/README.zh-CN.md b/README.zh-CN.md index aa3f06a0..fee9053a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -29,7 +29,7 @@ > Kotlin DSL ``` kotlin - val coskyVersion = "1.1.3"; + val coskyVersion = "1.1.5"; implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}") implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}") ``` @@ -46,7 +46,7 @@ 4.0.0 demo - 1.1.3 + 1.1.5 @@ -90,30 +90,30 @@ logging: #### 方式一:下载可执行文件 -> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.3/cosky-rest-api-1.1.3.tar) +> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.5/cosky-rest-api-1.1.5.tar) -> 解压 *cosky-rest-api-1.1.3.tar* +> 解压 *cosky-rest-api-1.1.5.tar* ```shell -cd cosky-rest-api-1.1.3 -# 工作目录: cosky-rest-api-1.1.3 +cd cosky-rest-api-1.1.5 +# 工作目录: cosky-rest-api-1.1.5 bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379 ``` #### 方式二:在 Docker 中运行 ```shell -docker pull ahoowang/cosky-rest-api:1.1.3 -docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3 +docker pull ahoowang/cosky-rest-api:1.1.5 +docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.5 ``` ##### MacBook Pro (M1) -> 请使用 *ahoowang/cosky-rest-api:1.1.3-armv7* +> 请使用 *ahoowang/cosky-rest-api:1.1.5-armv7* ```shell -docker pull ahoowang/cosky-rest-api:1.1.3-armv7 -docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.3-armv7 +docker pull ahoowang/cosky-rest-api:1.1.5-armv7 +docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.5-armv7 ``` #### 方式三:在 Kubernetes 中运行 @@ -141,7 +141,7 @@ spec: value: standalone - name: COSKY_REDIS_URI value: redis://redis-uri:6379 - image: ahoowang/cosky-rest-api:1.1.3 + image: ahoowang/cosky-rest-api:1.1.5 name: cosky-rest-api ports: - containerPort: 8080 @@ -275,12 +275,12 @@ spec: ``` shell gradle cosky-config:jmh # or -java -jar cosky-config/build/libs/cosky-config-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 +java -jar cosky-config/build/libs/cosky-config-1.1.5-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 ``` ``` # JMH version: 1.29 -# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS +# VM version: JDK 11.1.51, OpenJDK 64-Bit Server VM, 11.1.51+9-LTS # VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java # VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant # Blackhole mode: full + dont-inline hint @@ -301,12 +301,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132 ``` shell gradle cosky-discovery:jmh # or -java -jar cosky-discovery/build/libs/cosky-discovery-1.1.3-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 +java -jar cosky-discovery/build/libs/cosky-discovery-1.1.5-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1 ``` ``` # JMH version: 1.29 -# VM version: JDK 11.1.31, OpenJDK 64-Bit Server VM, 11.1.31+9-LTS +# VM version: JDK 11.1.51, OpenJDK 64-Bit Server VM, 11.1.51+9-LTS # VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java # VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant # Blackhole mode: full + dont-inline hint diff --git a/cosky-config/src/main/java/me/ahoo/cosky/config/ConfigKeyGenerator.java b/cosky-config/src/main/java/me/ahoo/cosky/config/ConfigKeyGenerator.java index 8fd4556e..d3811a9a 100644 --- a/cosky-config/src/main/java/me/ahoo/cosky/config/ConfigKeyGenerator.java +++ b/cosky-config/src/main/java/me/ahoo/cosky/config/ConfigKeyGenerator.java @@ -47,7 +47,7 @@ private ConfigKeyGenerator() { /** * {namespace}:{@link #CONFIG_IDX} * - * @param namespace + * @param namespace namespace * @return */ public static String getConfigIdxKey(String namespace) { diff --git a/cosky-config/src/main/java/me/ahoo/cosky/config/redis/ConfigRedisScripts.java b/cosky-config/src/main/java/me/ahoo/cosky/config/redis/ConfigRedisScripts.java index bc5e3bd8..1f79b160 100644 --- a/cosky-config/src/main/java/me/ahoo/cosky/config/redis/ConfigRedisScripts.java +++ b/cosky-config/src/main/java/me/ahoo/cosky/config/redis/ConfigRedisScripts.java @@ -2,7 +2,7 @@ import io.lettuce.core.RedisFuture; import io.lettuce.core.api.async.RedisScriptingAsyncCommands; -import me.ahoo.cosky.core.util.RedisScripts; +import me.ahoo.cosky.core.redis.RedisScripts; import java.util.concurrent.CompletableFuture; import java.util.function.Function; diff --git a/cosky-config/src/test/java/me/ahoo/cosky/config/redis/BaseOnRedisClientTest.java b/cosky-config/src/test/java/me/ahoo/cosky/config/redis/BaseOnRedisClientTest.java index 3b3574ed..234c8720 100644 --- a/cosky-config/src/test/java/me/ahoo/cosky/config/redis/BaseOnRedisClientTest.java +++ b/cosky-config/src/test/java/me/ahoo/cosky/config/redis/BaseOnRedisClientTest.java @@ -3,7 +3,7 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulRedisConnection; import lombok.var; -import me.ahoo.cosky.core.util.RedisScripts; +import me.ahoo.cosky.core.redis.RedisScripts; import org.junit.jupiter.api.*; import java.util.Objects; diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/listener/RedisClusterMessageListenable.java b/cosky-core/src/main/java/me/ahoo/cosky/core/listener/RedisClusterMessageListenable.java index ef33d6b9..8e3a42b7 100644 --- a/cosky-core/src/main/java/me/ahoo/cosky/core/listener/RedisClusterMessageListenable.java +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/listener/RedisClusterMessageListenable.java @@ -63,7 +63,7 @@ private class RedisClusterPubSubListenerAdapter implements RedisClusterPubSubLis @Override public void message(RedisClusterNode node, String channel, String message) { if (log.isDebugEnabled()){ - log.debug("Message received from a channel subscription - RedisNode[{}] | channel[{}] | message[{}].", node.getUri(), channel, message); + log.debug("Message received from a channel subscription - {} | channel[{}] | message[{}].", node, channel, message); } onMessage(channel, message, null); } @@ -79,7 +79,7 @@ public void message(RedisClusterNode node, String channel, String message) { @Override public void message(RedisClusterNode node, String pattern, String channel, String message) { if (log.isDebugEnabled()){ - log.debug("Message received from a pattern subscription - RedisNode[{}] | pattern[{}] | channel[{}] | message[{}].", node.getUri(), pattern, channel, message); + log.debug("Message received from a pattern subscription - {} | pattern[{}] | channel[{}] | message[{}].", node, pattern, channel, message); } onMessage(channel, message, pattern); } @@ -94,7 +94,7 @@ public void message(RedisClusterNode node, String pattern, String channel, Strin @Override public void subscribed(RedisClusterNode node, String channel, long count) { if (log.isInfoEnabled()){ - log.debug("Subscribed to a channel - RedisNode[{}] | channel[{}] | {}.", node.getUri(), channel, count); + log.debug("Subscribed to a channel - {} | channel[{}] | {}.", node, channel, count); } } @@ -108,7 +108,7 @@ public void subscribed(RedisClusterNode node, String channel, long count) { @Override public void psubscribed(RedisClusterNode node, String pattern, long count) { if (log.isInfoEnabled()){ - log.info("PSubscribed to a pattern - RedisNode[{}] | pattern[{}] | {}.", node.getUri(), pattern, count); + log.info("PSubscribed to a pattern - {} | pattern[{}] | {}.", node, pattern, count); } } @@ -122,7 +122,7 @@ public void psubscribed(RedisClusterNode node, String pattern, long count) { @Override public void unsubscribed(RedisClusterNode node, String channel, long count) { if (log.isInfoEnabled()){ - log.info("Unsubscribed from a channel - RedisNode[{}] | channel[{}] | {}.", node.getUri(), channel, count); + log.info("Unsubscribed from a channel - {} | channel[{}] | {}.", node, channel, count); } } @@ -137,7 +137,7 @@ public void unsubscribed(RedisClusterNode node, String channel, long count) { @Override public void punsubscribed(RedisClusterNode node, String pattern, long count) { if (log.isInfoEnabled()){ - log.info("PUnsubscribed from a pattern - RedisNode[{}] | pattern[{}] | {}.", node.getUri(), pattern, count); + log.info("PUnsubscribed from a pattern - {} | pattern[{}] | {}.", node, pattern, count); } } diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/RedisConfig.java b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConfig.java similarity index 50% rename from cosky-core/src/main/java/me/ahoo/cosky/core/RedisConfig.java rename to cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConfig.java index f0f2d35e..1a0c530b 100644 --- a/cosky-core/src/main/java/me/ahoo/cosky/core/RedisConfig.java +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConfig.java @@ -1,4 +1,4 @@ -package me.ahoo.cosky.core; +package me.ahoo.cosky.core.redis; /** * @author ahoo wang @@ -6,6 +6,8 @@ public class RedisConfig { private String url; private RedisMode mode; + private ReadFrom readFrom; + public String getUrl() { return url; } @@ -22,8 +24,28 @@ public void setMode(RedisMode mode) { this.mode = mode; } + public ReadFrom getReadFrom() { + return readFrom; + } + + public void setReadFrom(ReadFrom readFrom) { + this.readFrom = readFrom; + } + public enum RedisMode { STANDALONE, CLUSTER } + + public enum ReadFrom { + MASTER, + MASTER_PREFERRED, + UPSTREAM, + UPSTREAM_PREFERRED, + REPLICA_PREFERRED, + REPLICA, + NEAREST, + ANY, + ANY_REPLICA + } } diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnection.java b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnection.java new file mode 100644 index 00000000..482dbc58 --- /dev/null +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnection.java @@ -0,0 +1,31 @@ +package me.ahoo.cosky.core.redis; + +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; + + +/** + * @author ahoo wang + */ +public class RedisConnection implements AutoCloseable { + private StatefulConnection connection; + private RedisClusterAsyncCommands asyncCommands; + + public RedisConnection(StatefulConnection connection, RedisClusterAsyncCommands asyncCommands) { + this.connection = connection; + this.asyncCommands = asyncCommands; + } + + public StatefulConnection getConnection() { + return connection; + } + + public RedisClusterAsyncCommands getAsyncCommands() { + return asyncCommands; + } + + @Override + public void close() throws Exception { + connection.close(); + } +} diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnectionFactory.java b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnectionFactory.java new file mode 100644 index 00000000..42f0845a --- /dev/null +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisConnectionFactory.java @@ -0,0 +1,98 @@ +package me.ahoo.cosky.core.redis; + +import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.ReadFrom; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisURI; +import io.lettuce.core.cluster.RedisClusterClient; +import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; +import io.lettuce.core.codec.StringCodec; +import io.lettuce.core.masterreplica.MasterReplica; +import io.lettuce.core.masterreplica.StatefulRedisMasterReplicaConnection; +import io.lettuce.core.resource.ClientResources; +import lombok.extern.slf4j.Slf4j; +import lombok.var; +import me.ahoo.cosky.core.listener.MessageListenable; +import me.ahoo.cosky.core.listener.RedisClusterMessageListenable; +import me.ahoo.cosky.core.listener.RedisMessageListenable; + +import java.util.Objects; + +/** + * @author ahoo wang + */ +@Slf4j +public class RedisConnectionFactory implements AutoCloseable { + + private final ClientResources clientResources; + private final RedisConfig redisConfig; + private final AbstractRedisClient client; + private RedisConnection shareConnection; + + public RedisConnectionFactory(ClientResources clientResources, RedisConfig redisConfig) { + this.clientResources = clientResources; + this.redisConfig = redisConfig; + this.client = createClient(); + } + + private AbstractRedisClient createClient() { + if (RedisConfig.RedisMode.CLUSTER.equals(redisConfig.getMode())) { + return RedisClusterClient.create(clientResources, redisConfig.getUrl()); + } + return RedisClient.create(clientResources, redisConfig.getUrl()); + } + + public T getClient() { + return (T) client; + } + + public synchronized RedisConnection getShareConnection() { + if (Objects.nonNull(shareConnection)) { + return shareConnection; + } + + shareConnection = getConnection(); + return shareConnection; + } + + public synchronized RedisClusterAsyncCommands getShareAsyncCommands() { + return getShareConnection().getAsyncCommands(); + } + + public RedisConnection getConnection() { + + if (client instanceof RedisClusterClient) { + var clusterConnection = ((RedisClusterClient) client).connect(); + return new RedisConnection(clusterConnection, clusterConnection.async()); + } + + var redisClient = (RedisClient) client; + + if (Objects.isNull(redisConfig.getReadFrom())) { + var connection = redisClient.connect(); + return new RedisConnection(connection, connection.async()); + } + + ReadFrom readFrom = ReadFrom.valueOf(redisConfig.getReadFrom().name()); + + StatefulRedisMasterReplicaConnection connection = MasterReplica.connect(redisClient, StringCodec.UTF8, RedisURI.create(redisConfig.getUrl())); + connection.setReadFrom(readFrom); + return new RedisConnection(connection, connection.async()); + } + + public MessageListenable getMessageListenable() { + if (client instanceof RedisClusterClient) { + return new RedisClusterMessageListenable(((RedisClusterClient) client).connectPubSub()); + } + return new RedisMessageListenable(((RedisClient) client).connectPubSub()); + } + + @Override + public void close() throws Exception { + if (log.isInfoEnabled()) { + log.info("close."); + } + shareConnection.close(); + client.shutdown(); + } +} diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScriptInitializer.java b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScriptInitializer.java index de984e4d..7f59b68f 100644 --- a/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScriptInitializer.java +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScriptInitializer.java @@ -5,41 +5,29 @@ import io.lettuce.core.RedisConnectionStateListener; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import lombok.extern.slf4j.Slf4j; -import me.ahoo.cosky.core.util.RedisScripts; -import java.io.Closeable; import java.io.IOException; /** * @author ahoo wang */ @Slf4j -public class RedisScriptInitializer implements Closeable { +public class RedisScriptInitializer implements AutoCloseable { private final AbstractRedisClient redisClient; private final RedisStateListener redisStateListener; - public RedisScriptInitializer(AbstractRedisClient redisClient) { - this.redisClient = redisClient; + public RedisScriptInitializer(RedisConnectionFactory redisConnectionFactory) { + this.redisClient = redisConnectionFactory.getClient(); this.redisStateListener = new RedisStateListener(); redisClient.addListener(redisStateListener); } - /** - * Closes this stream and releases any system resources associated - * with it. If the stream is already closed then invoking this - * method has no effect. - * - *

As noted in {@link AutoCloseable#close()}, cases where the - * close may fail require careful attention. It is strongly advised - * to relinquish the underlying resources and to internally - * mark the {@code Closeable} as closed, prior to throwing - * the {@code IOException}. - * - * @throws IOException if an I/O error occurs - */ @Override public void close() throws IOException { + if (log.isInfoEnabled()){ + log.info("close - removeListener."); + } this.redisClient.removeListener(redisStateListener); } diff --git a/cosky-core/src/main/java/me/ahoo/cosky/core/util/RedisScripts.java b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScripts.java similarity index 96% rename from cosky-core/src/main/java/me/ahoo/cosky/core/util/RedisScripts.java rename to cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScripts.java index 8a3ad76e..3a07078e 100644 --- a/cosky-core/src/main/java/me/ahoo/cosky/core/util/RedisScripts.java +++ b/cosky-core/src/main/java/me/ahoo/cosky/core/redis/RedisScripts.java @@ -1,7 +1,8 @@ -package me.ahoo.cosky.core.util; +package me.ahoo.cosky.core.redis; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Charsets; +import com.google.common.hash.Hashing; import com.google.common.io.Resources; import io.lettuce.core.RedisFuture; import io.lettuce.core.RedisNoScriptException; @@ -49,7 +50,7 @@ public static CompletableFuture loadScript(String scriptName, RedisScrip } String script = getScript(key); - String scriptSha = scriptingCommands.digest(script); + String scriptSha = Hashing.sha1().hashString(script, Charsets.UTF_8).toString(); return scriptingCommands.scriptExists(scriptSha).thenCompose(existsList -> { boolean isExists = existsList.get(0); if (isExists) { diff --git a/cosky-core/src/test/java/me/ahoo/cosky/core/util/ScriptTest.java b/cosky-core/src/test/java/me/ahoo/cosky/core/util/ScriptTest.java index 129e4a6f..16f7ddc3 100644 --- a/cosky-core/src/test/java/me/ahoo/cosky/core/util/ScriptTest.java +++ b/cosky-core/src/test/java/me/ahoo/cosky/core/util/ScriptTest.java @@ -25,7 +25,6 @@ private void init() { @Test void testReturnBoolean() { - Boolean negativeOne = redisCommands.eval("return -1;", ScriptOutputType.BOOLEAN); Assertions.assertFalse(negativeOne); Boolean zero = redisCommands.eval("return 0;", ScriptOutputType.BOOLEAN); diff --git a/cosky-discovery/src/main/java/me/ahoo/cosky/discovery/redis/DiscoveryRedisScripts.java b/cosky-discovery/src/main/java/me/ahoo/cosky/discovery/redis/DiscoveryRedisScripts.java index aeb7b874..8371466b 100644 --- a/cosky-discovery/src/main/java/me/ahoo/cosky/discovery/redis/DiscoveryRedisScripts.java +++ b/cosky-discovery/src/main/java/me/ahoo/cosky/discovery/redis/DiscoveryRedisScripts.java @@ -2,7 +2,7 @@ import io.lettuce.core.RedisFuture; import io.lettuce.core.api.async.RedisScriptingAsyncCommands; -import me.ahoo.cosky.core.util.RedisScripts; +import me.ahoo.cosky.core.redis.RedisScripts; import java.util.concurrent.CompletableFuture; import java.util.function.Function; diff --git a/cosky-discovery/src/test/java/me/ahoo/cosky/discovery/BaseOnRedisClientTest.java b/cosky-discovery/src/test/java/me/ahoo/cosky/discovery/BaseOnRedisClientTest.java index b6430a02..bf40297e 100644 --- a/cosky-discovery/src/test/java/me/ahoo/cosky/discovery/BaseOnRedisClientTest.java +++ b/cosky-discovery/src/test/java/me/ahoo/cosky/discovery/BaseOnRedisClientTest.java @@ -3,7 +3,7 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulRedisConnection; import lombok.var; -import me.ahoo.cosky.core.util.RedisScripts; +import me.ahoo.cosky.core.redis.RedisScripts; import org.junit.jupiter.api.*; import java.util.Objects; diff --git a/cosky-rest-api/src/main/java/me/ahoo/cosky/rest/controller/StatController.java b/cosky-rest-api/src/main/java/me/ahoo/cosky/rest/controller/StatController.java index 55f773f2..73a6b7f8 100644 --- a/cosky-rest-api/src/main/java/me/ahoo/cosky/rest/controller/StatController.java +++ b/cosky-rest-api/src/main/java/me/ahoo/cosky/rest/controller/StatController.java @@ -22,13 +22,11 @@ public class StatController { private final NamespaceService namespaceService; - private final ServiceDiscovery serviceDiscovery; private final ConfigService configService; private final ServiceStatistic serviceStatistic; public StatController(NamespaceService namespaceService, ServiceDiscovery serviceDiscovery, ConfigService configService, ServiceStatistic serviceStatistic) { this.namespaceService = namespaceService; - this.serviceDiscovery = serviceDiscovery; this.configService = configService; this.serviceStatistic = serviceStatistic; } diff --git a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyAutoConfiguration.java b/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyAutoConfiguration.java index 5aae485a..a0cdb2a0 100644 --- a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyAutoConfiguration.java +++ b/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyAutoConfiguration.java @@ -1,12 +1,13 @@ package me.ahoo.cosky.spring.cloud; -import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.resource.ClientResources; +import io.lettuce.core.resource.DefaultClientResources; import me.ahoo.cosky.core.NamespaceService; import me.ahoo.cosky.core.NamespacedContext; +import me.ahoo.cosky.core.redis.RedisConnectionFactory; import me.ahoo.cosky.core.listener.MessageListenable; import me.ahoo.cosky.core.redis.RedisNamespaceService; import me.ahoo.cosky.core.redis.RedisScriptInitializer; -import me.ahoo.cosky.spring.cloud.support.RedisClientSupport; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -20,31 +21,43 @@ @EnableConfigurationProperties(CoskyProperties.class) public class CoskyAutoConfiguration { - public CoskyAutoConfiguration(CoskyProperties governProperties) { - NamespacedContext.GLOBAL.setCurrentContextNamespace(governProperties.getNamespace()); + public CoskyAutoConfiguration(CoskyProperties coskyProperties) { + NamespacedContext.GLOBAL.setCurrentContextNamespace(coskyProperties.getNamespace()); } @Bean(destroyMethod = "shutdown") + @ConditionalOnMissingBean(ClientResources.class) + public DefaultClientResources coskyClientResources() { + return DefaultClientResources.create(); + } + + @Bean @ConditionalOnMissingBean - public AbstractRedisClient redisClient(CoskyProperties governProperties) { - return RedisClientSupport.redisClient(governProperties.getRedis()); + public RedisConnectionFactory coskyRedisConnectionFactory(ClientResources clientResources, CoskyProperties coskyProperties) { + return new RedisConnectionFactory(clientResources, coskyProperties.getRedis()); } +// @Bean(destroyMethod = "shutdown") +// @ConditionalOnMissingBean +// public AbstractRedisClient redisClient(ClientResources clientResources, CoskyProperties governProperties) { +// return RedisClientSupport.redisClient(clientResources, governProperties.getRedis()); +// } + @Bean @ConditionalOnMissingBean - public RedisScriptInitializer redisScriptInitializer(AbstractRedisClient abstractRedisClient) { - return new RedisScriptInitializer(abstractRedisClient); + public RedisScriptInitializer redisScriptInitializer(RedisConnectionFactory redisConnectionFactory) { + return new RedisScriptInitializer(redisConnectionFactory); } @Bean @ConditionalOnMissingBean - public MessageListenable messageListenable(AbstractRedisClient redisClient) { - return RedisClientSupport.messageListenable(redisClient); + public MessageListenable messageListenable(RedisConnectionFactory redisConnectionFactory) { + return redisConnectionFactory.getMessageListenable(); } @Bean @ConditionalOnMissingBean - public NamespaceService namespaceService(AbstractRedisClient redisClient) { - return new RedisNamespaceService(RedisClientSupport.getRedisCommands(redisClient)); + public NamespaceService namespaceService(RedisConnectionFactory redisConnectionFactory) { + return new RedisNamespaceService(redisConnectionFactory.getShareAsyncCommands()); } } diff --git a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyProperties.java b/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyProperties.java index 2ef99037..f66e22b9 100644 --- a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyProperties.java +++ b/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/CoskyProperties.java @@ -2,7 +2,7 @@ import me.ahoo.cosky.core.Consts; import me.ahoo.cosky.core.NamespacedProperties; -import me.ahoo.cosky.core.RedisConfig; +import me.ahoo.cosky.core.redis.RedisConfig; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; diff --git a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/support/RedisClientSupport.java b/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/support/RedisClientSupport.java deleted file mode 100644 index 2234c00d..00000000 --- a/cosky-spring-cloud-core/src/main/java/me/ahoo/cosky/spring/cloud/support/RedisClientSupport.java +++ /dev/null @@ -1,40 +0,0 @@ -package me.ahoo.cosky.spring.cloud.support; - -import io.lettuce.core.AbstractRedisClient; -import io.lettuce.core.RedisClient; -import io.lettuce.core.cluster.RedisClusterClient; -import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; -import me.ahoo.cosky.core.RedisConfig; -import me.ahoo.cosky.core.listener.MessageListenable; -import me.ahoo.cosky.core.listener.RedisClusterMessageListenable; -import me.ahoo.cosky.core.listener.RedisMessageListenable; - -/** - * @author ahoo wang - */ -public final class RedisClientSupport { - private RedisClientSupport() { - } - - public static AbstractRedisClient redisClient(RedisConfig redisConfig) { - if (RedisConfig.RedisMode.CLUSTER.equals(redisConfig.getMode())) { - return RedisClusterClient.create(redisConfig.getUrl()); - } - return RedisClient.create(redisConfig.getUrl()); - } - - public static RedisClusterAsyncCommands getRedisCommands(AbstractRedisClient redisClient) { - if (redisClient instanceof RedisClusterClient) { - return ((RedisClusterClient) redisClient).connect().async(); - } else { - return ((RedisClient) redisClient).connect().async(); - } - } - - public static MessageListenable messageListenable(AbstractRedisClient redisClient) { - if (redisClient instanceof RedisClusterClient) { - return new RedisClusterMessageListenable(((RedisClusterClient) redisClient).connectPubSub()); - } - return new RedisMessageListenable(((RedisClient) redisClient).connectPubSub()); - } -} diff --git a/gradle.properties b/gradle.properties index 1a23c77f..66904411 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=me.ahoo.cosky -version=1.1.3 +version=1.1.5 description=CoSky On Redis (Service Discovery and Configuration Service) website=https://github.com/Ahoo-Wang/cosky diff --git a/k8s/deployment/cosky-mirror.yml b/k8s/deployment/cosky-mirror.yml index 527bb16f..9467046f 100644 --- a/k8s/deployment/cosky-mirror.yml +++ b/k8s/deployment/cosky-mirror.yml @@ -28,7 +28,7 @@ spec: value: nacos - name: SPRING_CLOUD_NACOS_PASSWORD value: nacos-pwd - image: ahoowang/cosky-mirror:1.1.3 + image: ahoowang/cosky-mirror:1.1.5 name: cosky-mirror resources: limits: diff --git a/k8s/deployment/cosky-rest-api.yml b/k8s/deployment/cosky-rest-api.yml index 6df8a6ef..749998e1 100644 --- a/k8s/deployment/cosky-rest-api.yml +++ b/k8s/deployment/cosky-rest-api.yml @@ -20,7 +20,7 @@ spec: value: standalone - name: COSKY_REDIS_URI value: redis://redis-uri:6379 - image: ahoowang/cosky-rest-api:1.1.3 + image: ahoowang/cosky-rest-api:1.1.5 name: cosky-rest-api ports: - containerPort: 8080 diff --git a/k8s/docker/cosky-mirror/Dockerfile b/k8s/docker/cosky-mirror/Dockerfile index d96c5a65..3902c1e4 100644 --- a/k8s/docker/cosky-mirror/Dockerfile +++ b/k8s/docker/cosky-mirror/Dockerfile @@ -1,8 +1,8 @@ -# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=armv7l-centos-jdk-11.0.11_9-slim -t ahoowang/cosky-mirror:1.1.3-armv7 . -# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-mirror:1.1.3 . +# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=armv7l-centos-jdk-11.0.11_9-slim -t ahoowang/cosky-mirror:1.1.5-armv7 . +# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-mirror:1.1.5 . ARG JDK_VERSION=jdk11u-centos-nightly-slim -ARG COSKY_VERSION=1.1.3 +ARG COSKY_VERSION=1.1.5 ARG COSKY_HOME=/cosky FROM adoptopenjdk/openjdk11:${JDK_VERSION} AS base diff --git a/k8s/docker/rest-api-local/Dockerfile b/k8s/docker/rest-api-local/Dockerfile index cf06b34b..abbbb356 100644 --- a/k8s/docker/rest-api-local/Dockerfile +++ b/k8s/docker/rest-api-local/Dockerfile @@ -1,8 +1,8 @@ -# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=armv7l-centos-jdk-11.0.11_9-slim -t ahoowang/cosky-rest-api:1.1.3-armv7 . -# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-rest-api:1.1.3 . +# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=armv7l-centos-jdk-11.0.11_9-slim -t ahoowang/cosky-rest-api:1.1.5-armv7 . +# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-rest-api:1.1.5 . ARG JDK_VERSION=jdk11u-centos-nightly-slim -ARG COSKY_VERSION=1.1.3 +ARG COSKY_VERSION=1.1.5 ARG COSKY_HOME=/cosky FROM adoptopenjdk/openjdk11:${JDK_VERSION} AS base diff --git a/k8s/docker/rest-api/Dockerfile b/k8s/docker/rest-api/Dockerfile index 4842b61c..fff9440f 100644 --- a/k8s/docker/rest-api/Dockerfile +++ b/k8s/docker/rest-api/Dockerfile @@ -1,8 +1,8 @@ -# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=armv7l-centos-jdk-11.1.31_9-slim -t ahoowang/cosky-rest-api:1.1.3-armv7 . -# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.3 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-rest-api:1.1.3 . +# docker buildx build --push --platform linux/arm/v7 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=armv7l-centos-jdk-11.1.51_9-slim -t ahoowang/cosky-rest-api:1.1.5-armv7 . +# docker buildx build --push --platform linux/amd64,linux/arm64 --build-arg COSKY_VERSION=1.1.5 --build-arg JDK_VERSION=jdk11u-centos-nightly-slim -t ahoowang/cosky-rest-api:1.1.5 . ARG JDK_VERSION=jdk11u-centos-nightly-slim -ARG COSKY_VERSION=1.1.3 +ARG COSKY_VERSION=1.1.5 ARG COSKY_HOME=/cosky FROM adoptopenjdk/openjdk11:${JDK_VERSION} AS base diff --git a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigAutoConfiguration.java b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigAutoConfiguration.java index 116e4e66..ef64c671 100644 --- a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigAutoConfiguration.java +++ b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigAutoConfiguration.java @@ -20,9 +20,9 @@ public CoskyConfigAutoConfiguration() { @Bean @ConditionalOnMissingBean - public CoskyConfigRefresher governConfigRefresher(CoskyProperties governProperties, + public CoskyConfigRefresher governConfigRefresher(CoskyProperties coskyProperties, CoskyConfigProperties configProperties, ConfigListenable configListenable) { - return new CoskyConfigRefresher(governProperties, configProperties, configListenable); + return new CoskyConfigRefresher(coskyProperties, configProperties, configListenable); } } diff --git a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigBootstrapConfiguration.java b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigBootstrapConfiguration.java index 972b7195..ceeff60f 100644 --- a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigBootstrapConfiguration.java +++ b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyConfigBootstrapConfiguration.java @@ -1,15 +1,14 @@ package me.ahoo.cosky.config.spring.cloud; -import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; import lombok.var; import me.ahoo.cosky.config.ConfigService; import me.ahoo.cosky.config.redis.ConsistencyRedisConfigService; import me.ahoo.cosky.config.redis.RedisConfigService; +import me.ahoo.cosky.core.redis.RedisConnectionFactory; import me.ahoo.cosky.core.listener.MessageListenable; import me.ahoo.cosky.spring.cloud.CoskyAutoConfiguration; import me.ahoo.cosky.spring.cloud.support.AppSupport; -import me.ahoo.cosky.spring.cloud.support.RedisClientSupport; import org.apache.logging.log4j.util.Strings; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -41,8 +40,8 @@ public CoskyConfigBootstrapConfiguration(CoskyConfigProperties governConfigPrope @Bean @ConditionalOnMissingBean public RedisConfigService redisConfigService( - AbstractRedisClient redisClient) { - RedisClusterAsyncCommands redisCommands = RedisClientSupport.getRedisCommands(redisClient); + RedisConnectionFactory redisConnectionFactory) { + RedisClusterAsyncCommands redisCommands =redisConnectionFactory.getShareAsyncCommands(); return new RedisConfigService(redisCommands); } diff --git a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyPropertySourceLocator.java b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyPropertySourceLocator.java index 1019072e..5d987b91 100644 --- a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyPropertySourceLocator.java +++ b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/CoskyPropertySourceLocator.java @@ -63,7 +63,7 @@ public PropertySource locate(Environment environment) { } var sourceLoader = ensureSourceLoader(fileExt); - var governPropertySource = getGovernPropertySourceOfConfig(sourceLoader, config); + var governPropertySource = getCoSkyPropertySourceOfConfig(sourceLoader, config); return governPropertySource; } @@ -86,7 +86,7 @@ public PropertySourceLoader ensureSourceLoader(String fileExtension) { * @return */ @SneakyThrows - public OriginTrackedMapPropertySource getGovernPropertySourceOfConfig(PropertySourceLoader sourceLoader, Config config) { + public OriginTrackedMapPropertySource getCoSkyPropertySourceOfConfig(PropertySourceLoader sourceLoader, Config config) { ByteArrayResource byteArrayResource = new ByteArrayResource(config.getData().getBytes(Charsets.UTF_8)); List> propertySourceList = sourceLoader.load(config.getConfigId(), byteArrayResource); Map source = getMapSource(config.getConfigId(), propertySourceList); diff --git a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/refresh/CoskyConfigRefresher.java b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/refresh/CoskyConfigRefresher.java index 6e9b996f..fadb0588 100644 --- a/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/refresh/CoskyConfigRefresher.java +++ b/spring-cloud-starter-cosky-config/src/main/java/me/ahoo/cosky/config/spring/cloud/refresh/CoskyConfigRefresher.java @@ -25,11 +25,11 @@ public class CoskyConfigRefresher implements ApplicationListener redisCommands = RedisClientSupport.getRedisCommands(redisClient); + RedisConnectionFactory redisConnectionFactory) { + RedisClusterAsyncCommands redisCommands = redisConnectionFactory.getShareAsyncCommands(); return new RedisServiceDiscovery(redisCommands); } @@ -51,9 +50,9 @@ public ConsistencyRedisServiceDiscovery consistencyRedisServiceDiscovery( @Bean @ConditionalOnMissingBean public RedisServiceStatistic redisServiceStatistic( - AbstractRedisClient redisClient, + RedisConnectionFactory redisConnectionFactory, MessageListenable messageListenable) { - RedisClusterAsyncCommands redisCommands = RedisClientSupport.getRedisCommands(redisClient); + RedisClusterAsyncCommands redisCommands = redisConnectionFactory.getShareAsyncCommands(); return new RedisServiceStatistic(redisCommands, messageListenable); } diff --git a/spring-cloud-starter-cosky-discovery/src/main/java/me/ahoo/cosky/discovery/spring/cloud/registry/CoskyAutoServiceRegistrationAutoConfiguration.java b/spring-cloud-starter-cosky-discovery/src/main/java/me/ahoo/cosky/discovery/spring/cloud/registry/CoskyAutoServiceRegistrationAutoConfiguration.java index 9147fdb3..37c27fbc 100644 --- a/spring-cloud-starter-cosky-discovery/src/main/java/me/ahoo/cosky/discovery/spring/cloud/registry/CoskyAutoServiceRegistrationAutoConfiguration.java +++ b/spring-cloud-starter-cosky-discovery/src/main/java/me/ahoo/cosky/discovery/spring/cloud/registry/CoskyAutoServiceRegistrationAutoConfiguration.java @@ -1,14 +1,13 @@ package me.ahoo.cosky.discovery.spring.cloud.registry; -import io.lettuce.core.AbstractRedisClient; import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; import lombok.var; +import me.ahoo.cosky.core.redis.RedisConnectionFactory; import me.ahoo.cosky.discovery.*; import me.ahoo.cosky.discovery.redis.RedisServiceRegistry; import me.ahoo.cosky.discovery.spring.cloud.discovery.ConditionalOnCoskyDiscoveryEnabled; import me.ahoo.cosky.discovery.spring.cloud.discovery.CoskyDiscoveryAutoConfiguration; import me.ahoo.cosky.spring.cloud.support.AppSupport; -import me.ahoo.cosky.spring.cloud.support.RedisClientSupport; import org.apache.logging.log4j.util.Strings; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -45,8 +44,8 @@ public RegistryProperties registryProperties( @Bean @Primary public RedisServiceRegistry redisServiceRegistry(RegistryProperties registryProperties, - AbstractRedisClient redisClient) { - RedisClusterAsyncCommands redisCommands = RedisClientSupport.getRedisCommands(redisClient); + RedisConnectionFactory redisConnectionFactory) { + RedisClusterAsyncCommands redisCommands = redisConnectionFactory.getShareAsyncCommands(); return new RedisServiceRegistry(registryProperties, redisCommands); }