From 4e2fb1b7a0d7439da0f14139c0e8e9d484a27a02 Mon Sep 17 00:00:00 2001
From: Mark Paluch
Date: Tue, 25 Apr 2017 14:39:30 +0200
Subject: [PATCH] DATAREDIS-626 - Polishing.
Refactor server and scripting commands to their own implementations and interfaces.
Fix JavaDoc indentations. Fix typos. Replace explicit type arguments with diamond syntax. Replace anonymous inner classes with method references and lambdas, where possible. Use shared ClientResources with LettuceConnectionFactory tests.
Align reactive command implementation visibility with blocking command implementation visibility to package-protected. These implementations are not an extension point and subject to be used through their interfaces.
Original pull request: #247.
---
src/main/asciidoc/new-features.adoc | 8 +-
.../connection/ClusterCommandExecutor.java | 32 +-
.../DefaultedRedisClusterConnection.java | 110 ++
.../connection/DefaultedRedisConnection.java | 232 ++++-
.../connection/RedisClusterConnection.java | 114 +-
.../RedisClusterServerCommands.java | 129 +++
.../redis/connection/RedisConnection.java | 40 +-
.../redis/connection/RedisServerCommands.java | 24 +-
.../jedis/JedisClusterConnection.java | 983 ++----------------
.../jedis/JedisClusterGeoCommands.java | 4 +-
.../jedis/JedisClusterHashCommands.java | 2 +-
.../jedis/JedisClusterKeyCommands.java | 100 +-
.../jedis/JedisClusterListCommands.java | 24 +-
.../jedis/JedisClusterScriptingCommands.java | 94 ++
.../jedis/JedisClusterServerCommands.java | 515 +++++++++
.../jedis/JedisClusterStringCommands.java | 22 +-
.../jedis/JedisClusterZSetCommands.java | 2 +-
.../connection/jedis/JedisConnection.java | 641 +-----------
.../jedis/JedisConnectionFactory.java | 63 +-
.../connection/jedis/JedisConverters.java | 63 +-
.../connection/jedis/JedisGeoCommands.java | 4 +-
.../connection/jedis/JedisHashCommands.java | 1 -
.../connection/jedis/JedisKeyCommands.java | 2 +-
.../jedis/JedisScriptReturnConverter.java | 6 +-
.../jedis/JedisScriptingCommands.java | 174 ++++
.../connection/jedis/JedisServerCommands.java | 505 +++++++++
.../connection/jedis/JedisSetCommands.java | 12 +-
.../connection/jedis/JedisStringCommands.java | 40 +-
.../redis/connection/jedis/JedisUtils.java | 28 +-
.../connection/jedis/JedisZSetCommands.java | 2 +-
.../lettuce/DefaultLettucePool.java | 35 +-
.../lettuce/LettuceClusterConnection.java | 653 ++----------
.../lettuce/LettuceClusterKeyCommands.java | 34 +-
.../lettuce/LettuceClusterListCommands.java | 6 +-
.../lettuce/LettuceClusterServerCommands.java | 378 +++++++
.../lettuce/LettuceClusterSetCommands.java | 13 +-
.../connection/lettuce/LettuceConnection.java | 681 ++----------
.../lettuce/LettuceConnectionFactory.java | 2 +-
.../connection/lettuce/LettuceConverters.java | 76 +-
.../lettuce/LettuceGeoCommands.java | 6 +-
.../lettuce/LettuceHashCommands.java | 2 +-
.../lettuce/LettuceHyperLogLogCommands.java | 2 +-
.../lettuce/LettuceKeyCommands.java | 2 +-
.../lettuce/LettuceListCommands.java | 2 +-
.../LettuceReactiveClusterGeoCommands.java | 3 +-
.../LettuceReactiveClusterHashCommands.java | 3 +-
...uceReactiveClusterHyperLogLogCommands.java | 8 +-
.../LettuceReactiveClusterKeyCommands.java | 3 +-
.../LettuceReactiveClusterListCommands.java | 9 +-
.../LettuceReactiveClusterNumberCommands.java | 2 +-
.../LettuceReactiveClusterSetCommands.java | 3 +-
.../LettuceReactiveClusterStringCommands.java | 8 +-
.../LettuceReactiveClusterZSetCommands.java | 9 +-
.../lettuce/LettuceReactiveGeoCommands.java | 2 +-
.../lettuce/LettuceReactiveHashCommands.java | 2 +-
.../LettuceReactiveHyperLogLogCommands.java | 8 +-
.../lettuce/LettuceReactiveKeyCommands.java | 2 +-
.../lettuce/LettuceReactiveListCommands.java | 2 +-
.../LettuceReactiveNumberCommands.java | 10 +-
...LettuceReactiveRedisClusterConnection.java | 2 +-
.../LettuceReactiveRedisConnection.java | 13 +-
.../lettuce/LettuceReactiveSetCommands.java | 4 +-
.../LettuceReactiveStringCommands.java | 2 +-
.../lettuce/LettuceReactiveZSetCommands.java | 2 +-
.../lettuce/LettuceScriptingCommands.java | 259 +++++
.../lettuce/LettuceServerCommands.java | 549 ++++++++++
.../lettuce/LettuceZSetCommands.java | 2 +-
.../redis/connection/jedis/ScanTests.java | 4 +-
.../LettuceConnectionFactoryTests.java | 3 +-
...eactiveHashOperationsIntegrationTests.java | 2 +
.../core/ReactiveOperationsTestParams.java | 2 +
.../redis/core/RedisKeyValueAdapterTests.java | 6 +-
.../core/RedisKeyValueTemplateTests.java | 8 +-
.../data/redis/core/RedisTemplateTests.java | 14 +-
.../mapping/Jackson2HashMapperTests.java | 7 +-
75 files changed, 3601 insertions(+), 3220 deletions(-)
create mode 100644 src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterScriptingCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptingCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/LettuceScriptingCommands.java
create mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java
diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc
index 80ccf0be6..d34879cef 100644
--- a/src/main/asciidoc/new-features.adoc
+++ b/src/main/asciidoc/new-features.adoc
@@ -9,7 +9,9 @@ New and noteworthy in the latest releases.
* Upgrade to Java 8.
* Removed support for SRP and JRedis drivers.
* Upgrade to `Lettuce` 5.0.
-* Reactive connection support using https://github.com/mp911de/lettuce[mp911de/lettuce]
+* Reactive connection support using https://github.com/lettuce-io/lettuce-core[lettuce-io/lettuce-core].
+* Introduce Redis feature-specific interfaces for `RedisConnection`.
+
[[new-in-1.8.0]]
== New in Spring Data Redis 1.8
@@ -30,7 +32,7 @@ New and noteworthy in the latest releases.
* Support for Spring Data Repository abstractions (see <>).
[[new-in-1-6-0]]
-== New in Spring Data Redis 1.6
+== New in Spring Data Redis 1.6
* The `Lettuce` Redis driver switched from https://github.com/wg/lettuce[wg/lettuce] to https://github.com/mp911de/lettuce[mp911de/lettuce].
* Support for `ZRANGEBYLEX`.
@@ -39,7 +41,7 @@ New and noteworthy in the latest releases.
* Generic Jackson2 `RedisSerializer` making use of Jackson's polymorphic deserialization.
[[new-in-1-5-0]]
-== New in Spring Data Redis 1.5
+== New in Spring Data Redis 1.5
* Add support for Redis HyperLogLog commands `PFADD`, `PFCOUNT` and `PFMERGE`.
* Configurable `JavaType` lookup for Jackson based `RedisSerializers`.
diff --git a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java
index f320d8bcf..38e80a94f 100644
--- a/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java
+++ b/src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java
@@ -15,21 +15,8 @@
*/
package org.springframework.data.redis.connection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -215,13 +202,7 @@ public class ClusterCommandExecutor implements DisposableBean {
Map>> futures = new LinkedHashMap>>();
for (final RedisClusterNode node : resolvedRedisClusterNodes) {
- futures.put(new NodeExecution(node), executor.submit(new Callable>() {
-
- @Override
- public NodeResult call() throws Exception {
- return executeCommandOnSingleNode(callback, node);
- }
- }));
+ futures.put(new NodeExecution(node), executor.submit(() -> executeCommandOnSingleNode(callback, node)));
}
return collectResults(futures);
@@ -310,13 +291,8 @@ public class ClusterCommandExecutor implements DisposableBean {
if (entry.getKey().isMaster()) {
for (final byte[] key : entry.getValue()) {
- futures.put(new NodeExecution(entry.getKey(), key), executor.submit(new Callable>() {
-
- @Override
- public NodeResult call() throws Exception {
- return executeMultiKeyCommandOnSingleNode(cmd, entry.getKey(), key);
- }
- }));
+ futures.put(new NodeExecution(entry.getKey(), key),
+ executor.submit(() -> executeMultiKeyCommandOnSingleNode(cmd, entry.getKey(), key)));
}
}
}
diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java
index 9695324bf..3312ee205 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java
@@ -15,10 +15,120 @@
*/
package org.springframework.data.redis.connection;
+import java.util.List;
+import java.util.Properties;
+
+import org.springframework.data.redis.core.types.RedisClientInfo;
+
/**
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 2.0
*/
public interface DefaultedRedisClusterConnection extends RedisClusterConnection, DefaultedRedisConnection {
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void bgReWriteAof(RedisClusterNode node) {
+ serverCommands().bgReWriteAof(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void bgSave(RedisClusterNode node) {
+ serverCommands().bgSave(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long lastSave(RedisClusterNode node) {
+ return serverCommands().lastSave(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void save(RedisClusterNode node) {
+ serverCommands().save(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long dbSize(RedisClusterNode node) {
+ return serverCommands().dbSize(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void flushDb(RedisClusterNode node) {
+ serverCommands().flushDb(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void flushAll(RedisClusterNode node) {
+ serverCommands().flushAll(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Properties info(RedisClusterNode node) {
+ return serverCommands().info(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Properties info(RedisClusterNode node, String section) {
+ return serverCommands().info(node, section);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void shutdown(RedisClusterNode node) {
+ serverCommands().shutdown(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default List getConfig(RedisClusterNode node, String pattern) {
+ return serverCommands().getConfig(node, pattern);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void setConfig(RedisClusterNode node, String param, String value) {
+ serverCommands().setConfig(node, param, value);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void resetConfigStats(RedisClusterNode node) {
+ serverCommands().resetConfigStats(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long time(RedisClusterNode node) {
+ return serverCommands().time(node);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default List getClientList(RedisClusterNode node) {
+ return serverCommands().getClientList(node);
+ }
}
diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
index 4a558cffe..0d286e16c 100644
--- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java
@@ -18,6 +18,7 @@ package org.springframework.data.redis.connection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -29,12 +30,16 @@ import org.springframework.data.geo.Point;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
+import org.springframework.data.redis.core.types.RedisClientInfo;
/**
- * {@link DefaultedRedisConnection} provides method delegates to {@code Redis*Command} interfaces accessible via {@link RedisConnection}.
- * This allows us to maintain backwards compatibility while moving the actual implementation and stay in sync with {@link ReactiveRedisConnection}.
- * Going forward the {@link RedisCommands} extension is likely to be removed from {@link RedisConnection}.
+ * {@link DefaultedRedisConnection} provides method delegates to {@code Redis*Command} interfaces accessible via
+ * {@link RedisConnection}. This allows us to maintain backwards compatibility while moving the actual implementation
+ * and stay in sync with {@link ReactiveRedisConnection}. Going forward the {@link RedisCommands} extension is likely to
+ * be removed from {@link RedisConnection}.
+ *
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 2.0
*/
public interface DefaultedRedisConnection extends RedisConnection {
@@ -1012,4 +1017,225 @@ public interface DefaultedRedisConnection extends RedisConnection {
default void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
hyperLogLogCommands().pfMerge(destinationKey, sourceKeys);
}
+
+ // SERVER COMMANDS
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void bgWriteAof() {
+ serverCommands().bgWriteAof();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void bgReWriteAof() {
+ serverCommands().bgReWriteAof();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void bgSave() {
+ serverCommands().bgSave();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long lastSave() {
+ return serverCommands().lastSave();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void save() {
+ serverCommands().save();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long dbSize() {
+ return serverCommands().dbSize();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void flushDb() {
+ serverCommands().flushDb();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void flushAll() {
+ serverCommands().flushAll();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Properties info() {
+ return serverCommands().info();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Properties info(String section) {
+ return serverCommands().info(section);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void shutdown() {
+ serverCommands().shutdown();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void shutdown(ShutdownOption option) {
+ serverCommands().shutdown(option);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default List getConfig(String pattern) {
+ return serverCommands().getConfig(pattern);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void setConfig(String param, String value) {
+ serverCommands().setConfig(param, value);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void resetConfigStats() {
+ serverCommands().resetConfigStats();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default Long time() {
+ return serverCommands().time();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void killClient(String host, int port) {
+ serverCommands().killClient(host, port);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void setClientName(byte[] name) {
+ serverCommands().setClientName(name);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default String getClientName() {
+ return serverCommands().getClientName();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default List getClientList() {
+ return serverCommands().getClientList();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void slaveOf(String host, int port) {
+ serverCommands().slaveOf(host, port);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void slaveOfNoOne() {
+ serverCommands().slaveOfNoOne();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option) {
+ serverCommands().migrate(key, target, dbIndex, option);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
+ @Override
+ @Deprecated
+ default void migrate(byte[] key, RedisNode target, int dbIndex, MigrateOption option, long timeout) {
+ serverCommands().migrate(key, target, dbIndex, option, timeout);
+ }
+
+ // SCRIPTING COMMANDS
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default void scriptFlush() {
+ scriptingCommands().scriptFlush();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default void scriptKill() {
+ scriptingCommands().scriptKill();
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default String scriptLoad(byte[] script) {
+ return scriptingCommands().scriptLoad(script);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default List scriptExists(String... scriptShas) {
+ return scriptingCommands().scriptExists(scriptShas);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
+ return scriptingCommands().eval(script, returnType, numKeys, keysAndArgs);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
+ return scriptingCommands().evalSha(scriptSha, returnType, numKeys, keysAndArgs);
+ }
+
+ /** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
+ @Override
+ @Deprecated
+ default T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
+ return scriptingCommands().evalSha(scriptSha, returnType, numKeys, keysAndArgs);
+ }
}
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/RedisClusterConnection.java
index 894f77823..765268fe3 100644
--- a/src/main/java/org/springframework/data/redis/connection/RedisClusterConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/RedisClusterConnection.java
@@ -15,23 +15,19 @@
*/
package org.springframework.data.redis.connection;
-import java.util.List;
-import java.util.Properties;
import java.util.Set;
-import org.springframework.data.redis.core.types.RedisClientInfo;
-
/**
* {@link RedisClusterConnection} allows sending commands to dedicated nodes within the cluster. A
* {@link RedisClusterNode} can be obtained from {@link #clusterGetNodes()} or it can be constructed using either
* {@link RedisClusterNode#getHost() host} and {@link RedisClusterNode#getPort()} or the {@link RedisClusterNode#getId()
* node Id}.
- *
+ *
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
-public interface RedisClusterConnection extends RedisConnection, RedisClusterCommands {
+public interface RedisClusterConnection extends RedisConnection, RedisClusterCommands, RedisClusterServerCommands {
/**
* @param node must not be {@literal null}.
@@ -40,65 +36,6 @@ public interface RedisClusterConnection extends RedisConnection, RedisClusterCom
*/
String ping(RedisClusterNode node);
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#bgReWriteAof()
- */
- void bgReWriteAof(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#bgSave()
- */
- void bgSave(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @return
- * @see RedisServerCommands#lastSave()
- */
- Long lastSave(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#save()
- */
- void save(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @return
- * @see RedisServerCommands#dbSize()
- */
- Long dbSize(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#flushDb()
- */
- void flushDb(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#flushAll()
- */
- void flushAll(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @return
- * @see RedisServerCommands#info()
- */
- Properties info(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @param section
- * @return
- * @see RedisServerCommands#info(String)
- */
- Properties info(RedisClusterNode node, String section);
-
/**
* @param node must not be {@literal null}.
* @param pattern must not be {@literal null}.
@@ -115,45 +52,12 @@ public interface RedisClusterConnection extends RedisConnection, RedisClusterCom
byte[] randomKey(RedisClusterNode node);
/**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#shutdown()
+ * Get {@link RedisClusterServerCommands}.
+ *
+ * @return never {@literal null}.
+ * @since 2.0
*/
- void shutdown(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @param pattern
- * @return
- * @see RedisServerCommands#getConfig(String)
- */
- List getConfig(RedisClusterNode node, String pattern);
-
- /**
- * @param node must not be {@literal null}.
- * @param param
- * @param value
- * @see RedisServerCommands#setConfig(String, String)
- */
- void setConfig(RedisClusterNode node, String param, String value);
-
- /**
- * @param node must not be {@literal null}.
- * @see RedisServerCommands#resetConfigStats()
- */
- void resetConfigStats(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @return
- * @see RedisServerCommands#time()
- */
- Long time(RedisClusterNode node);
-
- /**
- * @param node must not be {@literal null}.
- * @return
- * @see RedisServerCommands#getClientList()
- */
- public List getClientList(RedisClusterNode node);
-
+ default RedisClusterServerCommands serverCommands() {
+ return this;
+ }
}
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java
new file mode 100644
index 000000000..7c5c1b698
--- /dev/null
+++ b/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.redis.connection;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.springframework.data.redis.core.types.RedisClientInfo;
+
+/**
+ * @author Mark Paluch
+ * @since 2.0
+ */
+public interface RedisClusterServerCommands extends RedisServerCommands {
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#bgReWriteAof()
+ */
+ void bgReWriteAof(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#bgSave()
+ */
+ void bgSave(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @return
+ * @see RedisServerCommands#lastSave()
+ */
+ Long lastSave(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#save()
+ */
+ void save(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @return
+ * @see RedisServerCommands#dbSize()
+ */
+ Long dbSize(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#flushDb()
+ */
+ void flushDb(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#flushAll()
+ */
+ void flushAll(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @return
+ * @see RedisServerCommands#info()
+ */
+ Properties info(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @param section
+ * @return
+ * @see RedisServerCommands#info(String)
+ */
+ Properties info(RedisClusterNode node, String section);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#shutdown()
+ */
+ void shutdown(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @param pattern
+ * @return
+ * @see RedisServerCommands#getConfig(String)
+ */
+ List getConfig(RedisClusterNode node, String pattern);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @param param
+ * @param value
+ * @see RedisServerCommands#setConfig(String, String)
+ */
+ void setConfig(RedisClusterNode node, String param, String value);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @see RedisServerCommands#resetConfigStats()
+ */
+ void resetConfigStats(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @return
+ * @see RedisServerCommands#time()
+ */
+ Long time(RedisClusterNode node);
+
+ /**
+ * @param node must not be {@literal null}.
+ * @return
+ * @see RedisServerCommands#getClientList()
+ */
+ List getClientList(RedisClusterNode node);
+}
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisConnection.java b/src/main/java/org/springframework/data/redis/connection/RedisConnection.java
index 148b067e9..e4dda08c6 100644
--- a/src/main/java/org/springframework/data/redis/connection/RedisConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/RedisConnection.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.redis.connection;
import java.util.List;
@@ -24,9 +23,10 @@ import org.springframework.dao.DataAccessException;
* A connection to a Redis server. Acts as an common abstraction across various Redis client libraries (or drivers).
* Additionally performs exception translation between the underlying Redis client library and Spring DAO exceptions.
* The methods follow as much as possible the Redis names and conventions.
- *
+ *
* @author Costin Leau
* @author Christoph Strobl
+ * @author Mark Paluch
*/
public interface RedisConnection extends RedisCommands {
@@ -34,6 +34,7 @@ public interface RedisConnection extends RedisCommands {
* Get {@link RedisGeoCommands}.
*
* @return never {@literal null}.
+ * @since 2.0
*/
default RedisGeoCommands geoCommands() {
return this;
@@ -53,6 +54,7 @@ public interface RedisConnection extends RedisCommands {
* Get {@link RedisHyperLogLogCommands}.
*
* @return never {@literal null}.
+ * @since 2.0
*/
default RedisHyperLogLogCommands hyperLogLogCommands() {
return this;
@@ -88,6 +90,26 @@ public interface RedisConnection extends RedisCommands {
return this;
}
+ /**
+ * Get {@link RedisScriptingCommands}.
+ *
+ * @return never {@literal null}.
+ * @since 2.0
+ */
+ default RedisScriptingCommands scriptingCommands() {
+ return this;
+ }
+
+ /**
+ * Get {@link RedisServerCommands}.
+ *
+ * @return never {@literal null}.
+ * @since 2.0
+ */
+ default RedisServerCommands serverCommands() {
+ return this;
+ }
+
/**
* Get {@link RedisStringCommands}.
*
@@ -110,21 +132,21 @@ public interface RedisConnection extends RedisCommands {
/**
* Closes (or quits) the connection.
- *
+ *
* @throws DataAccessException
*/
void close() throws DataAccessException;
/**
* Indicates whether the underlying connection is closed or not.
- *
+ *
* @return true if the connection is closed, false otherwise.
*/
boolean isClosed();
/**
* Returns the native connection (the underlying library/driver object).
- *
+ *
* @return underlying, native object
*/
Object getNativeConnection();
@@ -133,14 +155,14 @@ public interface RedisConnection extends RedisCommands {
* Indicates whether the connection is in "queue"(or "MULTI") mode or not. When queueing, all commands are postponed
* until EXEC or DISCARD commands are issued. Since in queueing no results are returned, the connection will return
* NULL on all operations that interact with the data.
- *
+ *
* @return true if the connection is in queue/MULTI mode, false otherwise
*/
boolean isQueueing();
/**
* Indicates whether the connection is currently pipelined or not.
- *
+ *
* @return true if the connection is pipelined, false otherwise
* @see #openPipeline()
* @see #isQueueing()
@@ -158,7 +180,7 @@ public interface RedisConnection extends RedisCommands {
*
* Consider doing some performance testing before using this feature since in many cases the performance benefits are
* minimal yet the impact on usage are not.
- *
+ *
* @see #multi()
*/
void openPipeline();
@@ -166,7 +188,7 @@ public interface RedisConnection extends RedisCommands {
/**
* Executes the commands in the pipeline and returns their result. If the connection is not pipelined, an empty
* collection is returned.
- *
+ *
* @throws RedisPipelineException if the pipeline contains any incorrect/invalid statements
* @return the result of the executed commands.
*/
diff --git a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java
index fe9e3f269..e9c5d9cee 100644
--- a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java
+++ b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java
@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@ import org.springframework.data.redis.core.types.RedisClientInfo;
/**
* Server-specific commands supported by Redis.
- *
+ *
* @author Costin Leau
* @author Christoph Strobl
* @author Thomas Darimont
@@ -43,12 +43,14 @@ public interface RedisServerCommands {
/**
* Start an {@literal Append Only File} rewrite process on server.
- *
+ *
* @deprecated As of 1.3, use {@link #bgReWriteAof}.
* @see Redis Documentation: BGREWRITEAOF
*/
@Deprecated
- void bgWriteAof();
+ default void bgWriteAof() {
+ bgReWriteAof();
+ }
/**
* Start an {@literal Append Only File} rewrite process on server.
@@ -110,7 +112,7 @@ public interface RedisServerCommands {
*
replication
*
*
- *
+ *
* @return
* @see Redis Documentation: INFO
*/
@@ -167,7 +169,7 @@ public interface RedisServerCommands {
/**
* Request server timestamp using {@code TIME} command.
- *
+ *
* @return current server time in milliseconds.
* @since 1.1
* @see Redis Documentation: TIME
@@ -176,7 +178,7 @@ public interface RedisServerCommands {
/**
* Closes a given client connection identified by {@literal host:port}.
- *
+ *
* @param host of connection to close.
* @param port of connection to close
* @since 1.3
@@ -186,7 +188,7 @@ public interface RedisServerCommands {
/**
* Assign given name to current connection.
- *
+ *
* @param name
* @since 1.3
* @see Redis Documentation: CLIENT SETNAME
@@ -232,7 +234,7 @@ public interface RedisServerCommands {
/**
* Atomically transfer a key from a source Redis instance to a destination Redis instance. On success the key is
* deleted from the original instance and is guaranteed to exist in the target instance.
- *
+ *
* @param key must not be {@literal null}.
* @param target must not be {@literal null}.
* @param dbIndex
diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java
index b8ffb96ae..608bd9d52 100644
--- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java
+++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java
@@ -15,20 +15,18 @@
*/
package org.springframework.data.redis.connection.jedis;
+import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
import java.util.Set;
import org.springframework.beans.DirectFieldAccessor;
@@ -37,37 +35,13 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.ClusterStateFailureException;
import org.springframework.data.redis.ExceptionTranslationStrategy;
import org.springframework.data.redis.PassThroughExceptionTranslationStrategy;
-import org.springframework.data.redis.connection.ClusterCommandExecutor;
+import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.connection.ClusterCommandExecutor.ClusterCommandCallback;
import org.springframework.data.redis.connection.ClusterCommandExecutor.MultiKeyClusterCommandCallback;
import org.springframework.data.redis.connection.ClusterCommandExecutor.NodeResult;
-import org.springframework.data.redis.connection.ClusterInfo;
-import org.springframework.data.redis.connection.ClusterNodeResourceProvider;
-import org.springframework.data.redis.connection.ClusterTopology;
-import org.springframework.data.redis.connection.ClusterTopologyProvider;
-import org.springframework.data.redis.connection.DefaultedRedisClusterConnection;
-import org.springframework.data.redis.connection.MessageListener;
-import org.springframework.data.redis.connection.RedisClusterConnection;
-import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
-import org.springframework.data.redis.connection.RedisGeoCommands;
-import org.springframework.data.redis.connection.RedisHashCommands;
-import org.springframework.data.redis.connection.RedisHyperLogLogCommands;
-import org.springframework.data.redis.connection.RedisKeyCommands;
-import org.springframework.data.redis.connection.RedisListCommands;
-import org.springframework.data.redis.connection.RedisNode;
-import org.springframework.data.redis.connection.RedisPipelineException;
-import org.springframework.data.redis.connection.RedisSentinelConnection;
-import org.springframework.data.redis.connection.RedisSetCommands;
-import org.springframework.data.redis.connection.RedisStringCommands;
-import org.springframework.data.redis.connection.RedisSubscribedConnectionException;
-import org.springframework.data.redis.connection.RedisZSetCommands;
-import org.springframework.data.redis.connection.ReturnType;
-import org.springframework.data.redis.connection.Subscription;
import org.springframework.data.redis.connection.convert.Converters;
-import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
-import org.springframework.util.CollectionUtils;
/**
* {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.
@@ -95,7 +69,7 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
/**
* Create new {@link JedisClusterConnection} utilizing native connections via {@link JedisCluster}.
- *
+ *
* @param cluster must not be {@literal null}.
*/
public JedisClusterConnection(JedisCluster cluster) {
@@ -147,46 +121,96 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
throw new UnsupportedOperationException("Execute is currently not supported in cluster mode.");
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#geoCommands()
+ */
@Override
public RedisGeoCommands geoCommands() {
return new JedisClusterGeoCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#hashCommands()
+ */
@Override
public RedisHashCommands hashCommands() {
return new JedisClusterHashCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#hyperLogLogCommands()
+ */
@Override
public RedisHyperLogLogCommands hyperLogLogCommands() {
return new JedisClusterHyperLogLogCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#keyCommands()
+ */
@Override
public RedisKeyCommands keyCommands() {
return doGetKeyCommands();
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#stringCommands()
+ */
@Override
public RedisStringCommands stringCommands() {
return new JedisClusterStringCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#listCommands()
+ */
@Override
public RedisListCommands listCommands() {
return new JedisClusterListCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#setCommands()
+ */
@Override
public RedisSetCommands setCommands() {
return new JedisClusterSetCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#zSetCommands()
+ */
@Override
public RedisZSetCommands zSetCommands() {
return new JedisClusterZSetCommands(this);
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisClusterConnection#serverCommands()
+ */
+ @Override
+ public RedisClusterServerCommands serverCommands() {
+ return new JedisClusterServerCommands(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.redis.connection.RedisConnection#scriptingCommands()
+ */
+ @Override
+ public RedisScriptingCommands scriptingCommands() {
+ return JedisClusterScriptingCommands.INSTANCE;
+ }
+
private JedisClusterKeyCommands doGetKeyCommands() {
return new JedisClusterKeyCommands(this);
}
@@ -342,13 +366,9 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
@Override
public String ping() {
- return !clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.ping();
- }
- }).resultsAsList().isEmpty() ? "PONG" : null;
+ return !clusterCommandExecutor
+ .executeCommandOnAllNodes((JedisClusterCommandCallback) BinaryJedis::ping).resultsAsList()
+ .isEmpty() ? "PONG" : null;
}
@@ -359,717 +379,8 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
@Override
public String ping(RedisClusterNode node) {
- return clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.ping();
- }
- }, node).getValue();
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#bgWriteAof()
- */
- @Override
- public void bgWriteAof() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.bgrewriteaof();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#bgReWriteAof(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public void bgReWriteAof(RedisClusterNode node) {
-
- clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.bgrewriteaof();
- }
- }, node);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#bgReWriteAof()
- */
- @Override
- public void bgReWriteAof() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.bgrewriteaof();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#bgSave()
- */
- @Override
- public void bgSave() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.bgsave();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#bgSave(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public void bgSave(RedisClusterNode node) {
-
- clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.bgsave();
- }
- }, node);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#lastSave()
- */
- @Override
- public Long lastSave() {
-
- List result = new ArrayList(
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public Long doInCluster(Jedis client) {
- return client.lastsave();
- }
- }).resultsAsList());
-
- if (CollectionUtils.isEmpty(result)) {
- return null;
- }
-
- Collections.sort(result, Collections.reverseOrder());
- return result.get(0);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#lastSave(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public Long lastSave(RedisClusterNode node) {
-
- return clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public Long doInCluster(Jedis client) {
- return client.lastsave();
- }
- }, node).getValue();
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#save()
- */
- @Override
- public void save() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.save();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#save(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public void save(RedisClusterNode node) {
-
- clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.save();
- }
- }, node);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#dbSize()
- */
- @Override
- public Long dbSize() {
-
- Collection dbSizes = clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public Long doInCluster(Jedis client) {
- return client.dbSize();
- }
- }).resultsAsList();
-
- if (CollectionUtils.isEmpty(dbSizes)) {
- return 0L;
- }
-
- Long size = 0L;
- for (Long value : dbSizes) {
- size += value;
- }
- return size;
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#dbSize(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public Long dbSize(RedisClusterNode node) {
-
- return clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public Long doInCluster(Jedis client) {
- return client.dbSize();
- }
- }, node).getValue();
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#flushDb()
- */
- @Override
- public void flushDb() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.flushDB();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#flushDb(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public void flushDb(RedisClusterNode node) {
-
- clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.flushDB();
- }
- }, node);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#flushAll()
- */
- @Override
- public void flushAll() {
-
- clusterCommandExecutor.executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.flushAll();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisClusterConnection#flushAll(org.springframework.data.redis.connection.RedisClusterNode)
- */
- @Override
- public void flushAll(RedisClusterNode node) {
-
- clusterCommandExecutor.executeCommandOnSingleNode(new JedisClusterCommandCallback() {
-
- @Override
- public String doInCluster(Jedis client) {
- return client.flushAll();
- }
- }, node);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.redis.connection.RedisServerCommands#info()
- */
- @Override
- public Properties info() {
-
- Properties infos = new Properties();
-
- List> nodeResults = clusterCommandExecutor
- .executeCommandOnAllNodes(new JedisClusterCommandCallback() {
-
- @Override
- public Properties doInCluster(Jedis client) {
- return JedisConverters.toProperties(client.info());
- }
- }).getResults();
-
- for (NodeResult nodePorperties : nodeResults) {
- for (Entry