Skip to content

Commit a462f34

Browse files
committed
Finish keyless KEYS command impl
1 parent f4b5707 commit a462f34

21 files changed

+462
-163
lines changed

src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,15 +2095,43 @@ public RedisFuture<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSi
20952095
}
20962096

20972097
@Override
2098-
public RedisFuture<List<K>> keys(String pattern) {
2098+
public RedisFuture<List<String>> keys(String pattern) {
20992099
return dispatch(commandBuilder.keys(pattern));
21002100
}
21012101

2102+
/**
2103+
* Find all keys matching the given pattern (legacy overload).
2104+
*
2105+
* @param pattern the pattern type: patternkey (pattern).
2106+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
2107+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
2108+
*/
2109+
@Deprecated
2110+
@Override
2111+
public RedisFuture<List<K>> keysLegacy(K pattern) {
2112+
return dispatch(commandBuilder.keysLegacy(pattern));
2113+
}
2114+
21022115
@Override
2103-
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
2116+
public RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern) {
21042117
return dispatch(commandBuilder.keys(channel, pattern));
21052118
}
21062119

2120+
/**
2121+
* Find all keys matching the given pattern (legacy overload).
2122+
*
2123+
* @param channel the channel.
2124+
* @param pattern the pattern.
2125+
* @return Long array-reply list of keys matching {@code pattern}.
2126+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
2127+
* version.
2128+
*/
2129+
@Deprecated
2130+
@Override
2131+
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
2132+
return dispatch(commandBuilder.keysLegacy(channel, pattern));
2133+
}
2134+
21072135
@Override
21082136
public RedisFuture<Date> lastsave() {
21092137
return dispatch(commandBuilder.lastsave());

src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,15 +2160,43 @@ public Mono<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSimArgs a
21602160
}
21612161

21622162
@Override
2163-
public Flux<K> keys(String pattern) {
2163+
public Flux<String> keys(String pattern) {
21642164
return createDissolvingFlux(() -> commandBuilder.keys(pattern));
21652165
}
21662166

2167+
/**
2168+
* Find all keys matching the given pattern (legacy overload).
2169+
*
2170+
* @param pattern the pattern type: patternkey (pattern).
2171+
* @return K array-reply list of keys matching {@code pattern}.
2172+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
2173+
*/
2174+
@Deprecated
2175+
@Override
2176+
public Flux<K> keysLegacy(K pattern) {
2177+
return createDissolvingFlux(() -> commandBuilder.keysLegacy(pattern));
2178+
}
2179+
21672180
@Override
2168-
public Mono<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
2181+
public Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern) {
21692182
return createMono(() -> commandBuilder.keys(channel, pattern));
21702183
}
21712184

2185+
/**
2186+
* Find all keys matching the given pattern (legacy overload).
2187+
*
2188+
* @param channel the channel.
2189+
* @param pattern the pattern.
2190+
* @return Long array-reply list of keys matching {@code pattern}.
2191+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
2192+
* version.
2193+
*/
2194+
@Deprecated
2195+
@Override
2196+
public Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
2197+
return createMono(() -> commandBuilder.keysLegacy(channel, pattern));
2198+
}
2199+
21722200
@Override
21732201
public Mono<Date> lastsave() {
21742202
return createMono(commandBuilder::lastsave);

src/main/java/io/lettuce/core/RedisCommandBuilder.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,19 +1942,52 @@ Command<K, V, String> info(String section) {
19421942
return createCommand(CommandType.INFO, new StatusOutput<>(codec), args);
19431943
}
19441944

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

1948-
CommandArgs<K, V> args = new CommandArgs<>(codec).addGlobalPattern(pattern);
1949-
return createCommand(KEYS, new GlobPatternOutput<>(codec), args);
1948+
CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
1949+
return createCommand(KEYS, new StringListOutput<>(codec), args);
19501950
}
19511951

1952-
Command<K, V, Long> keys(KeyStreamingChannel<K> channel, String pattern) {
1952+
/**
1953+
* Find all keys matching the given pattern (legacy overload).
1954+
*
1955+
* @param pattern the pattern type: patternkey (pattern).
1956+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
1957+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
1958+
*/
1959+
@Deprecated
1960+
Command<K, V, List<K>> keysLegacy(K pattern) {
1961+
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
1962+
1963+
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(pattern);
1964+
return createCommand(KEYS, new KeyListOutput<>(codec), args);
1965+
}
1966+
1967+
Command<K, V, Long> keys(KeyStreamingChannel<String> channel, String pattern) {
1968+
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
1969+
notNull(channel);
1970+
1971+
CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
1972+
return createCommand(KEYS, new StringStreamingOutput<>(codec, channel), args);
1973+
}
1974+
1975+
/**
1976+
* Find all keys matching the given pattern (legacy overload).
1977+
*
1978+
* @param channel the channel.
1979+
* @param pattern the pattern.
1980+
* @return Long array-reply list of keys matching {@code pattern}.
1981+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
1982+
* version.
1983+
*/
1984+
@Deprecated
1985+
Command<K, V, Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
19531986
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
19541987
notNull(channel);
19551988

1956-
CommandArgs<K, V> args = new CommandArgs<>(codec).addGlobalPattern(pattern);
1957-
return createCommand(KEYS, new GlobPatternStreamingOutput<>(codec, channel), args);
1989+
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(pattern);
1990+
return createCommand(KEYS, new KeyStreamingOutput<>(codec, channel), args);
19581991
}
19591992

19601993
Command<K, V, Date> lastsave() {

src/main/java/io/lettuce/core/api/async/RedisKeyAsyncCommands.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,43 @@ public interface RedisKeyAsyncCommands<K, V> {
218218
* Find all keys matching the given pattern.
219219
*
220220
* @param pattern the pattern type: patternkey (pattern).
221+
* @return List&lt;String&gt; array-reply list of keys matching {@code pattern}.
222+
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
223+
*/
224+
RedisFuture<List<String>> keys(String pattern);
225+
226+
/**
227+
* Find all keys matching the given pattern (legacy overload).
228+
*
229+
* @param pattern the pattern type: patternkey (pattern).
221230
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
231+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
222232
*/
223-
RedisFuture<List<K>> keys(String pattern);
233+
@Deprecated
234+
RedisFuture<List<K>> keysLegacy(K pattern);
224235

225236
/**
226237
* Find all keys matching the given pattern.
227238
*
228239
* @param channel the channel.
229240
* @param pattern the pattern.
230241
* @return Long array-reply list of keys matching {@code pattern}.
242+
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
243+
* {@link #keys(KeyStreamingChannel, String)}.
244+
*/
245+
RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern);
246+
247+
/**
248+
* Find all keys matching the given pattern (legacy overload).
249+
*
250+
* @param channel the channel.
251+
* @param pattern the pattern.
252+
* @return Long array-reply list of keys matching {@code pattern}.
253+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
254+
* version.
231255
*/
232-
RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern);
256+
@Deprecated
257+
RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);
233258

234259
/**
235260
* Atomically transfer a key from a Redis instance to another one.

src/main/java/io/lettuce/core/api/reactive/RedisKeyReactiveCommands.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,48 @@ public interface RedisKeyReactiveCommands<K, V> {
228228
* Find all keys matching the given pattern.
229229
*
230230
* @param pattern the pattern type: patternkey (pattern).
231+
* @return String array-reply list of keys matching {@code pattern}.
232+
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
233+
*/
234+
Flux<String> keys(String pattern);
235+
236+
/**
237+
* Find all keys matching the given pattern (legacy overload).
238+
*
239+
* @param pattern the pattern type: patternkey (pattern).
231240
* @return K array-reply list of keys matching {@code pattern}.
241+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
232242
*/
233-
Flux<K> keys(String pattern);
243+
@Deprecated
244+
Flux<K> keysLegacy(K pattern);
234245

235246
/**
236247
* Find all keys matching the given pattern.
237248
*
238249
* @param channel the channel.
239250
* @param pattern the pattern.
240251
* @return Long array-reply list of keys matching {@code pattern}.
252+
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
253+
* {@link #keys(KeyStreamingChannel, String)}.
241254
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
242255
* {@link #keys}.
243256
*/
244257
@Deprecated
245-
Mono<Long> keys(KeyStreamingChannel<K> channel, String pattern);
258+
Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern);
259+
260+
/**
261+
* Find all keys matching the given pattern (legacy overload).
262+
*
263+
* @param channel the channel.
264+
* @param pattern the pattern.
265+
* @return Long array-reply list of keys matching {@code pattern}.
266+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
267+
* version.
268+
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
269+
* {@link #keysLegacy}.
270+
*/
271+
@Deprecated
272+
Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);
246273

247274
/**
248275
* Atomically transfer a key from a Redis instance to another one.

src/main/java/io/lettuce/core/api/sync/RedisKeyCommands.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,43 @@ public interface RedisKeyCommands<K, V> {
227227
* Find all keys matching the given pattern.
228228
*
229229
* @param pattern the pattern type: patternkey (pattern).
230+
* @return List&lt;String&gt; array-reply list of keys matching {@code pattern}.
231+
* @implNote {@code keysLegacy(K)} is deprecated and will be removed in a later version. Prefer {@link #keys(String)}.
232+
*/
233+
List<String> keys(String pattern);
234+
235+
/**
236+
* Find all keys matching the given pattern (legacy overload).
237+
*
238+
* @param pattern the pattern type: patternkey (pattern).
230239
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
240+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
231241
*/
232-
List<K> keys(String pattern);
242+
@Deprecated
243+
List<K> keysLegacy(K pattern);
233244

234245
/**
235246
* Find all keys matching the given pattern.
236247
*
237248
* @param channel the channel.
238249
* @param pattern the pattern.
239250
* @return Long array-reply list of keys matching {@code pattern}.
251+
* @implNote {@code keysLegacy(KeyStreamingChannel, K)} is deprecated and will be removed in a later version. Prefer
252+
* {@link #keys(KeyStreamingChannel, String)}.
253+
*/
254+
Long keys(KeyStreamingChannel<String> channel, String pattern);
255+
256+
/**
257+
* Find all keys matching the given pattern (legacy overload).
258+
*
259+
* @param channel the channel.
260+
* @param pattern the pattern.
261+
* @return Long array-reply list of keys matching {@code pattern}.
262+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
263+
* version.
240264
*/
241-
Long keys(KeyStreamingChannel<K> channel, String pattern);
265+
@Deprecated
266+
Long keysLegacy(KeyStreamingChannel<K> channel, K pattern);
242267

243268
/**
244269
* Atomically transfer a key from a Redis instance to another one.

src/main/java/io/lettuce/core/cluster/RedisAdvancedClusterAsyncCommandsImpl.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,31 @@ public RedisFuture<String> flushdb(FlushMode flushMode) {
276276
}
277277

278278
@Override
279-
public RedisFuture<List<K>> keys(String pattern) {
279+
public RedisFuture<List<String>> keys(String pattern) {
280280

281-
Map<String, CompletableFuture<List<K>>> executions = executeOnUpstream(commands -> commands.keys(pattern));
281+
Map<String, CompletableFuture<List<String>>> executions = executeOnUpstream(commands -> commands.keys(pattern));
282+
283+
return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
284+
List<String> result = new ArrayList<>();
285+
for (CompletableFuture<List<String>> future : executions.values()) {
286+
result.addAll(MultiNodeExecution.execute(future::get));
287+
}
288+
return result;
289+
});
290+
}
291+
292+
/**
293+
* Find all keys matching the given pattern (legacy overload).
294+
*
295+
* @param pattern the pattern type: patternkey (pattern).
296+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
297+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
298+
*/
299+
@Deprecated
300+
@Override
301+
public RedisFuture<List<K>> keysLegacy(K pattern) {
302+
303+
Map<String, CompletableFuture<List<K>>> executions = executeOnUpstream(commands -> commands.keysLegacy(pattern));
282304

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

292314
@Override
293-
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
315+
public RedisFuture<Long> keys(KeyStreamingChannel<String> channel, String pattern) {
294316

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

321+
/**
322+
* Find all keys matching the given pattern (legacy overload).
323+
*
324+
* @param channel the channel.
325+
* @param pattern the pattern.
326+
* @return Long array-reply list of keys matching {@code pattern}.
327+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
328+
* version.
329+
*/
330+
@Deprecated
331+
@Override
332+
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
333+
334+
Map<String, CompletableFuture<Long>> executions = executeOnUpstream(commands -> commands.keysLegacy(channel, pattern));
335+
return MultiNodeExecution.aggregateAsync(executions);
336+
}
337+
299338
@Override
300339
public RedisFuture<List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys) {
301340
Map<Integer, List<K>> partitioned = SlotHash.partition(codec, Arrays.asList(keys));

0 commit comments

Comments
 (0)