From f47006a903f15a7295d79563b58512ec18bf5dc0 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 1 Dec 2015 15:45:05 +0300 Subject: [PATCH] RKeysReactive.findKeysByPattern added. #210 --- .../java/org/redisson/RedissonKeysReactive.java | 16 ++++++++++++++++ .../java/org/redisson/core/RKeysReactive.java | 17 +++++++++++++++++ .../org/redisson/RedissonKeysReactiveTest.java | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/src/main/java/org/redisson/RedissonKeysReactive.java b/src/main/java/org/redisson/RedissonKeysReactive.java index 56833c86d..b46ad8a93 100644 --- a/src/main/java/org/redisson/RedissonKeysReactive.java +++ b/src/main/java/org/redisson/RedissonKeysReactive.java @@ -150,6 +150,22 @@ 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.readAllObservable(RedisCommands.KEYS, pattern); + } + @Override public Publisher randomKey() { return commandExecutor.readRandomObservable(RedisCommands.RANDOM_KEY); diff --git a/src/main/java/org/redisson/core/RKeysReactive.java b/src/main/java/org/redisson/core/RKeysReactive.java index 60ef15221..f0a36158a 100644 --- a/src/main/java/org/redisson/core/RKeysReactive.java +++ b/src/main/java/org/redisson/core/RKeysReactive.java @@ -15,8 +15,12 @@ */ package org.redisson.core; +import java.util.Collection; + import org.reactivestreams.Publisher; +import io.netty.util.concurrent.Future; + public interface RKeysReactive { Publisher getKeys(); @@ -32,6 +36,19 @@ public interface RKeysReactive { */ Publisher getSlot(String key); + /** + * 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 + */ + Publisher> findKeysByPattern(String pattern); + /** * Get random key in mode * diff --git a/src/test/java/org/redisson/RedissonKeysReactiveTest.java b/src/test/java/org/redisson/RedissonKeysReactiveTest.java index 796442992..a6f08f67c 100644 --- a/src/test/java/org/redisson/RedissonKeysReactiveTest.java +++ b/src/test/java/org/redisson/RedissonKeysReactiveTest.java @@ -1,12 +1,17 @@ package org.redisson; +import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Assert; import org.junit.Test; +import org.redisson.core.RBucket; import org.redisson.core.RBucketReactive; +import org.redisson.core.RMap; import org.redisson.core.RMapReactive; public class RedissonKeysReactiveTest extends BaseReactiveTest {