Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2095,15 +2095,43 @@ public RedisFuture<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSi
}

@Override
public RedisFuture<List<K>> keys(K pattern) {
public RedisFuture<List<String>> keys(String pattern) {
return dispatch(commandBuilder.keys(pattern));
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
@Deprecated
@Override
public RedisFuture<List<K>> keysLegacy(K pattern) {
return dispatch(commandBuilder.keysLegacy(pattern));
}

@Override
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
public RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern) {
return dispatch(commandBuilder.keys(channel, pattern));
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
@Deprecated
@Override
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
return dispatch(commandBuilder.keysLegacy(channel, pattern));
}

@Override
public RedisFuture<Date> lastsave() {
return dispatch(commandBuilder.lastsave());
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2160,15 +2160,43 @@ public Mono<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSimArgs a
}

@Override
public Flux<K> keys(K pattern) {
public Flux<String> keys(String pattern) {
return createDissolvingFlux(() -> commandBuilder.keys(pattern));
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return K array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
@Deprecated
@Override
public Flux<K> keysLegacy(K pattern) {
return createDissolvingFlux(() -> commandBuilder.keysLegacy(pattern));
}

@Override
public Mono<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
public Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern) {
return createMono(() -> commandBuilder.keys(channel, pattern));
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
@Deprecated
@Override
public Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
return createMono(() -> commandBuilder.keysLegacy(channel, pattern));
}

@Override
public Mono<Date> lastsave() {
return createMono(commandBuilder::lastsave);
Expand Down
43 changes: 39 additions & 4 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1942,17 +1942,52 @@ Command<K, V, String> info(String section) {
return createCommand(CommandType.INFO, new StatusOutput<>(codec), args);
}

Command<K, V, List<K>> keys(K pattern) {
Command<K, V, List<String>> keys(String pattern) {
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);

return createCommand(KEYS, new KeyListOutput<>(codec), pattern);
CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
return createCommand(KEYS, new StringListOutput<>(codec), args);
}

Command<K, V, Long> keys(KeyStreamingChannel<K> channel, K pattern) {
/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
@Deprecated
Command<K, V, List<K>> keysLegacy(K pattern) {
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(pattern);
return createCommand(KEYS, new KeyListOutput<>(codec), args);
}

Command<K, V, Long> keys(KeyStreamingChannel<String> channel, String pattern) {
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
notNull(channel);

CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
return createCommand(KEYS, new StringStreamingOutput<>(codec, channel), args);
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
@Deprecated
Command<K, V, Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
notNull(channel);

return createCommand(KEYS, new KeyStreamingOutput<>(codec, channel), pattern);
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(pattern);
return createCommand(KEYS, new KeyStreamingOutput<>(codec, channel), args);
}

Command<K, V, Date> lastsave() {
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,43 @@ public interface RedisKeyAsyncCommands<K, V> {
* Find all keys matching the given pattern.
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;String&gt; array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
*/
RedisFuture<List<String>> keys(String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
RedisFuture<List<K>> keys(K pattern);
@Deprecated
RedisFuture<List<K>> keysLegacy(K pattern);

/**
* Find all keys matching the given pattern.
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
* {@link #keys(KeyStreamingChannel, String)}.
*/
RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern);
@Deprecated
RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);

/**
* Atomically transfer a key from a Redis instance to another one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,48 @@ public interface RedisKeyReactiveCommands<K, V> {
* Find all keys matching the given pattern.
*
* @param pattern the pattern type: patternkey (pattern).
* @return String array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
*/
Flux<String> keys(String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return K array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
Flux<K> keys(K pattern);
@Deprecated
Flux<K> keysLegacy(K pattern);

/**
* Find all keys matching the given pattern.
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
* {@link #keys(KeyStreamingChannel, String)}.
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
* {@link #keys}.
*/
@Deprecated
Mono<Long> keys(KeyStreamingChannel<K> channel, K pattern);
Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
* {@link #keysLegacy}.
*/
@Deprecated
Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);

/**
* Atomically transfer a key from a Redis instance to another one.
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,43 @@ public interface RedisKeyCommands<K, V> {
* Find all keys matching the given pattern.
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;String&gt; array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
*/
List<String> keys(String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
List<K> keys(K pattern);
@Deprecated
List<K> keysLegacy(K pattern);

/**
* Find all keys matching the given pattern.
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
* {@link #keys(KeyStreamingChannel, String)}.
*/
Long keys(KeyStreamingChannel<String> channel, String pattern);

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
Long keys(KeyStreamingChannel<K> channel, K pattern);
@Deprecated
Long keysLegacy(KeyStreamingChannel<K> channel, K pattern);

/**
* Atomically transfer a key from a Redis instance to another one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,31 @@ public RedisFuture<String> flushdb(FlushMode flushMode) {
}

@Override
public RedisFuture<List<K>> keys(K pattern) {
public RedisFuture<List<String>> keys(String pattern) {

Map<String, CompletableFuture<List<K>>> executions = executeOnUpstream(commands -> commands.keys(pattern));
Map<String, CompletableFuture<List<String>>> executions = executeOnUpstream(commands -> commands.keys(pattern));

return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
List<String> result = new ArrayList<>();
for (CompletableFuture<List<String>> future : executions.values()) {
result.addAll(MultiNodeExecution.execute(future::get));
}
return result;
});
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param pattern the pattern type: patternkey (pattern).
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
*/
@Deprecated
@Override
public RedisFuture<List<K>> keysLegacy(K pattern) {

Map<String, CompletableFuture<List<K>>> executions = executeOnUpstream(commands -> commands.keysLegacy(pattern));

return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
List<K> result = new ArrayList<>();
Expand All @@ -290,12 +312,29 @@ public RedisFuture<List<K>> keys(K pattern) {
}

@Override
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
public RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern) {

Map<String, CompletableFuture<Long>> executions = executeOnUpstream(commands -> commands.keys(channel, pattern));
return MultiNodeExecution.aggregateAsync(executions);
}

/**
* Find all keys matching the given pattern (legacy overload).
*
* @param channel the channel.
* @param pattern the pattern.
* @return Long array-reply list of keys matching {@code pattern}.
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
* version.
*/
@Deprecated
@Override
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {

Map<String, CompletableFuture<Long>> executions = executeOnUpstream(commands -> commands.keysLegacy(channel, pattern));
return MultiNodeExecution.aggregateAsync(executions);
}

@Override
public RedisFuture<List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys) {
Map<Integer, List<K>> partitioned = SlotHash.partition(codec, Arrays.asList(keys));
Expand Down
Loading