Skip to content
Merged
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 @@ -2108,15 +2108,43 @@ public RedisFuture<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSi
}

@Override
public RedisFuture<List<K>> keys(K pattern) {
public RedisFuture<List<K>> 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<K> 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 @@ -2174,15 +2174,43 @@ public Mono<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSimArgs a
}

@Override
public Flux<K> keys(K pattern) {
public Flux<K> 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<K> 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
37 changes: 35 additions & 2 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need different output ?

Original file line number Diff line number Diff line change
Expand Up @@ -1942,13 +1942,46 @@ 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<K>> keys(String pattern) {
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);

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

/**
* 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);

return createCommand(KEYS, new KeyListOutput<>(codec), pattern);
}

Command<K, V, Long> keys(KeyStreamingChannel<K> channel, K pattern) {
Command<K, V, Long> keys(KeyStreamingChannel<K> 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 KeyStreamingOutput<>(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);

Expand Down
26 changes: 24 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 @@ -217,19 +217,41 @@ public interface RedisKeyAsyncCommands<K, V> {
/**
* Find all keys matching the given pattern.
*
* @param pattern the pattern type.
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
*/
RedisFuture<List<K>> 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 type.
* @return Long array-reply list of keys matching {@code pattern}.
*/
RedisFuture<Long> keys(KeyStreamingChannel<K> 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 @@ -227,22 +227,45 @@ public interface RedisKeyReactiveCommands<K, V> {
/**
* Find all keys matching the given pattern.
*
* @param pattern the pattern type.
* @return K flux of keys matching {@code pattern}.
*/
Flux<K> 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.
* @param pattern the pattern type.
* @return Long array-reply list of keys matching {@code pattern}.
* @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<K> 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(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
26 changes: 24 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 @@ -226,19 +226,41 @@ public interface RedisKeyCommands<K, V> {
/**
* Find all keys matching the given pattern.
*
* @param pattern the pattern type.
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
*/
List<K> 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 type.
* @return Long array-reply list of keys matching {@code pattern}.
*/
Long keys(KeyStreamingChannel<K> 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 @@ -296,7 +296,7 @@ public RedisFuture<String> flushdb(FlushMode flushMode) {
}

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

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

Expand All @@ -309,13 +309,52 @@ public RedisFuture<List<K>> keys(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
@Override
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
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<>();
for (CompletableFuture<List<K>> future : executions.values()) {
result.addAll(MultiNodeExecution.execute(future::get));
}
return result;
});
}

@Override
public RedisFuture<Long> keys(KeyStreamingChannel<K> 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
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,50 @@ public Mono<String> flushdb(FlushMode flushMode) {
}

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

Map<String, Publisher<K>> publishers = executeOnUpstream(commands -> commands.keys(pattern));
return Flux.merge(publishers.values());
}

/**
* 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) {

Map<String, Publisher<K>> publishers = executeOnUpstream(commands -> commands.keysLegacy(pattern));
return Flux.merge(publishers.values());
}

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

Map<String, Publisher<Long>> publishers = executeOnUpstream(commands -> commands.keys(channel, pattern));
return Flux.merge(publishers.values()).reduce((accu, next) -> accu + next);
}

/**
* 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(String)} instead. This legacy overload will be removed in a later version.
*/
@Deprecated
@Override
public Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {

Map<String, Publisher<Long>> publishers = executeOnUpstream(commands -> commands.keysLegacy(channel, pattern));
return Flux.merge(publishers.values()).reduce((accu, next) -> accu + next);
}

@Override
public Flux<KeyValue<K, V>> mget(K... keys) {
return mget(Arrays.asList(keys));
Expand Down
Loading