diff --git a/src/main/java/org/redisson/RedissonReactive.java b/src/main/java/org/redisson/RedissonReactive.java index d515abb69..9d7824f79 100644 --- a/src/main/java/org/redisson/RedissonReactive.java +++ b/src/main/java/org/redisson/RedissonReactive.java @@ -18,7 +18,6 @@ package org.redisson; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.UUID; import org.redisson.api.RAtomicLongReactive; import org.redisson.api.RBatchReactive; @@ -47,6 +46,9 @@ import org.redisson.connection.ElasticacheConnectionManager; import org.redisson.connection.MasterSlaveConnectionManager; import org.redisson.connection.SentinelConnectionManager; import org.redisson.connection.SingleConnectionManager; +import org.redisson.core.ClusterNode; +import org.redisson.core.Node; +import org.redisson.core.NodesGroup; import org.redisson.reactive.RedissonAtomicLongReactive; import org.redisson.reactive.RedissonBatchReactive; import org.redisson.reactive.RedissonBitSetReactive; @@ -80,8 +82,6 @@ public class RedissonReactive implements RedissonReactiveClient { private final ConnectionManager connectionManager; private final Config config; - private final UUID id = UUID.randomUUID(); - RedissonReactive(Config config) { this.config = config; Config configCopy = new Config(config); @@ -262,23 +262,28 @@ public class RedissonReactive implements RedissonReactiveClient { return new RedissonKeysReactive(commandExecutor); } + @Override public Config getConfig() { return config; } @Override - public void shutdown() { - connectionManager.shutdown(); + public NodesGroup getNodesGroup() { + return new RedisNodes(connectionManager); } @Override - public void flushdb() { - commandExecutor.get(commandExecutor.writeAllAsync(RedisCommands.FLUSHDB)); + public NodesGroup getClusterNodesGroup() { + if (!config.isClusterConfig()) { + throw new IllegalStateException("Redisson not in cluster mode!"); + } + return new RedisNodes(connectionManager); } @Override - public void flushall() { - commandExecutor.get(commandExecutor.writeAllAsync(RedisCommands.FLUSHALL)); + public void shutdown() { + connectionManager.shutdown(); } + } diff --git a/src/main/java/org/redisson/api/RKeysReactive.java b/src/main/java/org/redisson/api/RKeysReactive.java index 07d4d2d7a..1d60a8867 100644 --- a/src/main/java/org/redisson/api/RKeysReactive.java +++ b/src/main/java/org/redisson/api/RKeysReactive.java @@ -19,17 +19,38 @@ import java.util.Collection; import org.reactivestreams.Publisher; -import io.netty.util.concurrent.Future; - public interface RKeysReactive { + /** + * Load keys in incrementally iterate mode. + * + * Uses SCAN Redis command. + * + * @param pattern + * @return + */ Publisher getKeys(); + /** + * Find keys by pattern and load it in incrementally iterate mode. + * + * Uses SCAN Redis command. + * + * Supported glob-style patterns: + * h?llo subscribes to hello, hallo and hxllo + * h*llo subscribes to hllo and heeeello + * h[ae]llo subscribes to hello and hallo, but not hillo + * + * @param pattern + * @return + */ Publisher getKeysByPattern(String pattern); /** - * Get hash slot identifier for key in mode. - * Available for cluster nodes only + * Get hash slot identifier for key. + * Available for cluster nodes only. + * + * Uses KEYSLOT Redis command. * * @param key * @return @@ -37,7 +58,9 @@ public interface RKeysReactive { Publisher getSlot(String key); /** - * Find keys by key search pattern by one Redis call + * Find keys by key search pattern by one Redis call. + * + * Uses KEYS Redis command. * * Supported glob-style patterns: * h?llo subscribes to hello, hallo and hxllo @@ -50,14 +73,18 @@ public interface RKeysReactive { Publisher> findKeysByPattern(String pattern); /** - * Get random key in mode + * Get random key + * + * Uses RANDOM_KEY Redis command. * * @return */ Publisher randomKey(); /** - * Delete multiple objects by a key pattern in mode + * Delete multiple objects by a key pattern. + * + * Uses Lua script. * * Supported glob-style patterns: * h?llo subscribes to hello, hallo and hxllo @@ -70,11 +97,29 @@ public interface RKeysReactive { Publisher deleteByPattern(String pattern); /** - * Delete multiple objects by name in mode + * Delete multiple objects by name. + * + * Uses DEL Redis command. * * @param keys - object names * @return */ Publisher delete(String ... keys); + /** + * Delete all the keys of the currently selected database + * + * Uses FLUSHDB Redis command. + * + */ + Publisher flushdb(); + + /** + * Delete all the keys of all the existing databases + * + * Uses FLUSHALL Redis command. + * + */ + Publisher flushall(); + } diff --git a/src/main/java/org/redisson/api/RedissonReactiveClient.java b/src/main/java/org/redisson/api/RedissonReactiveClient.java index cc2704dc4..1e247f8cc 100644 --- a/src/main/java/org/redisson/api/RedissonReactiveClient.java +++ b/src/main/java/org/redisson/api/RedissonReactiveClient.java @@ -19,6 +19,9 @@ import java.util.List; import org.redisson.Config; import org.redisson.client.codec.Codec; +import org.redisson.core.ClusterNode; +import org.redisson.core.Node; +import org.redisson.core.NodesGroup; public interface RedissonReactiveClient { @@ -201,28 +204,18 @@ public interface RedissonReactiveClient { */ Config getConfig(); -// /** -// * Get Redis nodes group for server operations -// * -// * @return -// */ -// NodesGroup getNodesGroup(); -// -// /** -// * Get Redis cluster nodes group for server operations -// * -// * @return -// */ -// NodesGroup getClusterNodesGroup(); -// /** - * Delete all the keys of the currently selected database + * Get Redis nodes group for server operations + * + * @return */ - void flushdb(); + NodesGroup getNodesGroup(); /** - * Delete all the keys of all the existing databases + * Get Redis cluster nodes group for server operations + * + * @return */ - void flushall(); + NodesGroup getClusterNodesGroup(); } diff --git a/src/main/java/org/redisson/reactive/RedissonKeysReactive.java b/src/main/java/org/redisson/reactive/RedissonKeysReactive.java index 6f68b7c5f..ac49e1fe2 100644 --- a/src/main/java/org/redisson/reactive/RedissonKeysReactive.java +++ b/src/main/java/org/redisson/reactive/RedissonKeysReactive.java @@ -151,17 +151,6 @@ public class RedissonKeysReactive implements RKeysReactive { }; } - /** - * Find keys by key search pattern by one Redis call - * - * Supported glob-style patterns: - * h?llo subscribes to hello, hallo and hxllo - * h*llo subscribes to hllo and heeeello - * h[ae]llo subscribes to hello and hallo, but not hillo - * - * @param pattern - * @return - */ @Override public Publisher> findKeysByPattern(String pattern) { return commandExecutor.readAllReactive(RedisCommands.KEYS, pattern); @@ -172,17 +161,6 @@ public class RedissonKeysReactive implements RKeysReactive { return commandExecutor.readRandomReactive(RedisCommands.RANDOM_KEY); } - /** - * Delete multiple objects by a key pattern - * - * Supported glob-style patterns: - * h?llo subscribes to hello, hallo and hxllo - * h*llo subscribes to hllo and heeeello - * h[ae]llo subscribes to hello and hallo, but not hillo - * - * @param pattern - * @return - */ @Override public Publisher deleteByPattern(String pattern) { return commandExecutor.evalWriteAllReactive(RedisCommands.EVAL_LONG, new SlotCallback() { @@ -204,12 +182,6 @@ public class RedissonKeysReactive implements RKeysReactive { + "return n;",Collections.emptyList(), pattern); } - /** - * Delete multiple objects by name - * - * @param keys - object names - * @return - */ @Override public Publisher delete(String ... keys) { return commandExecutor.writeAllReactive(RedisCommands.DEL, new SlotCallback() { @@ -226,5 +198,14 @@ public class RedissonKeysReactive implements RKeysReactive { }, (Object[])keys); } + @Override + public Publisher flushdb() { + return commandExecutor.writeAllReactive(RedisCommands.FLUSHDB); + } + + @Override + public Publisher flushall() { + return commandExecutor.writeAllReactive(RedisCommands.FLUSHALL); + } }