Skip to content

Commit 5dafb95

Browse files
Dltmd202a-TODO-rovuglide
authored
The KEYS command needs to be keyless (#3341)
* The KEYS command needs to be keyless * Finish keyless KEYS command impl * Rm useless line in legacy KEYS build * Remove Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern) - deprecated since 6.0 * Fix test * Revert "Fix test" This reverts commit a0a3dfe. * Revert - Remove Mono<Long> keys(KeyStreamingChannel<String> channel, String pattern) - deprecated since 6.0 * Revert - return type to K * Fix javadoc --------- Co-authored-by: aleksandar.todorov <[email protected]> Co-authored-by: Igor Malinovskiy <[email protected]>
1 parent 91afb94 commit 5dafb95

17 files changed

+411
-44
lines changed

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

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

21102110
@Override
2111-
public RedisFuture<List<K>> keys(K pattern) {
2111+
public RedisFuture<List<K>> keys(String pattern) {
21122112
return dispatch(commandBuilder.keys(pattern));
21132113
}
21142114

2115+
/**
2116+
* Find all keys matching the given pattern (legacy overload).
2117+
*
2118+
* @param pattern the pattern type: patternkey (pattern).
2119+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
2120+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
2121+
*/
2122+
@Deprecated
2123+
@Override
2124+
public RedisFuture<List<K>> keysLegacy(K pattern) {
2125+
return dispatch(commandBuilder.keysLegacy(pattern));
2126+
}
2127+
21152128
@Override
2116-
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
2129+
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
21172130
return dispatch(commandBuilder.keys(channel, pattern));
21182131
}
21192132

2133+
/**
2134+
* Find all keys matching the given pattern (legacy overload).
2135+
*
2136+
* @param channel the channel.
2137+
* @param pattern the pattern.
2138+
* @return Long array-reply list of keys matching {@code pattern}.
2139+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
2140+
* version.
2141+
*/
2142+
@Deprecated
2143+
@Override
2144+
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
2145+
return dispatch(commandBuilder.keysLegacy(channel, pattern));
2146+
}
2147+
21202148
@Override
21212149
public RedisFuture<Date> lastsave() {
21222150
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
@@ -2174,15 +2174,43 @@ public Mono<Map<V, VSimScoreAttribs>> vsimWithScoreWithAttribs(K key, VSimArgs a
21742174
}
21752175

21762176
@Override
2177-
public Flux<K> keys(K pattern) {
2177+
public Flux<K> keys(String pattern) {
21782178
return createDissolvingFlux(() -> commandBuilder.keys(pattern));
21792179
}
21802180

2181+
/**
2182+
* Find all keys matching the given pattern (legacy overload).
2183+
*
2184+
* @param pattern the pattern type: patternkey (pattern).
2185+
* @return K array-reply list of keys matching {@code pattern}.
2186+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
2187+
*/
2188+
@Deprecated
2189+
@Override
2190+
public Flux<K> keysLegacy(K pattern) {
2191+
return createDissolvingFlux(() -> commandBuilder.keysLegacy(pattern));
2192+
}
2193+
21812194
@Override
2182-
public Mono<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
2195+
public Mono<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
21832196
return createMono(() -> commandBuilder.keys(channel, pattern));
21842197
}
21852198

2199+
/**
2200+
* Find all keys matching the given pattern (legacy overload).
2201+
*
2202+
* @param channel the channel.
2203+
* @param pattern the pattern.
2204+
* @return Long array-reply list of keys matching {@code pattern}.
2205+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
2206+
* version.
2207+
*/
2208+
@Deprecated
2209+
@Override
2210+
public Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
2211+
return createMono(() -> commandBuilder.keysLegacy(channel, pattern));
2212+
}
2213+
21862214
@Override
21872215
public Mono<Date> lastsave() {
21882216
return createMono(commandBuilder::lastsave);

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,46 @@ 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(K pattern) {
1945+
Command<K, V, List<K>> keys(String pattern) {
1946+
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
1947+
1948+
CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
1949+
return createCommand(KEYS, new KeyListOutput<>(codec), args);
1950+
}
1951+
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) {
19461961
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
19471962

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

1951-
Command<K, V, Long> keys(KeyStreamingChannel<K> channel, K pattern) {
1966+
Command<K, V, Long> keys(KeyStreamingChannel<K> channel, String pattern) {
1967+
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
1968+
notNull(channel);
1969+
1970+
CommandArgs<K, V> args = new CommandArgs<>(codec).add(pattern);
1971+
return createCommand(KEYS, new KeyStreamingOutput<>(codec, channel), args);
1972+
}
1973+
1974+
/**
1975+
* Find all keys matching the given pattern (legacy overload).
1976+
*
1977+
* @param channel the channel.
1978+
* @param pattern the pattern.
1979+
* @return Long array-reply list of keys matching {@code pattern}.
1980+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
1981+
* version.
1982+
*/
1983+
@Deprecated
1984+
Command<K, V, Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
19521985
LettuceAssert.notNull(pattern, "Pattern " + MUST_NOT_BE_NULL);
19531986
notNull(channel);
19541987

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,41 @@ public interface RedisKeyAsyncCommands<K, V> {
217217
/**
218218
* Find all keys matching the given pattern.
219219
*
220+
* @param pattern the pattern type.
221+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
222+
*/
223+
RedisFuture<List<K>> keys(String pattern);
224+
225+
/**
226+
* Find all keys matching the given pattern (legacy overload).
227+
*
220228
* @param pattern the pattern type: patternkey (pattern).
221229
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
230+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
222231
*/
223-
RedisFuture<List<K>> keys(K pattern);
232+
@Deprecated
233+
RedisFuture<List<K>> keysLegacy(K pattern);
224234

225235
/**
226236
* Find all keys matching the given pattern.
227237
*
228238
* @param channel the channel.
239+
* @param pattern the pattern type.
240+
* @return Long array-reply list of keys matching {@code pattern}.
241+
*/
242+
RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern);
243+
244+
/**
245+
* Find all keys matching the given pattern (legacy overload).
246+
*
247+
* @param channel the channel.
229248
* @param pattern the pattern.
230249
* @return Long array-reply list of keys matching {@code pattern}.
250+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
251+
* version.
231252
*/
232-
RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern);
253+
@Deprecated
254+
RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);
233255

234256
/**
235257
* Atomically transfer a key from a Redis instance to another one.

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,45 @@ public interface RedisKeyReactiveCommands<K, V> {
227227
/**
228228
* Find all keys matching the given pattern.
229229
*
230+
* @param pattern the pattern type.
231+
* @return K flux of keys matching {@code pattern}.
232+
*/
233+
Flux<K> keys(String pattern);
234+
235+
/**
236+
* Find all keys matching the given pattern (legacy overload).
237+
*
230238
* @param pattern the pattern type: patternkey (pattern).
231239
* @return K 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.
232241
*/
233-
Flux<K> keys(K pattern);
242+
@Deprecated
243+
Flux<K> keysLegacy(K pattern);
234244

235245
/**
236246
* Find all keys matching the given pattern.
237247
*
238248
* @param channel the channel.
239-
* @param pattern the pattern.
249+
* @param pattern the pattern type.
240250
* @return Long array-reply list of keys matching {@code pattern}.
241251
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
242252
* {@link #keys}.
243253
*/
244254
@Deprecated
245-
Mono<Long> keys(KeyStreamingChannel<K> channel, K pattern);
255+
Mono<Long> keys(KeyStreamingChannel<K> channel, String pattern);
256+
257+
/**
258+
* Find all keys matching the given pattern (legacy overload).
259+
*
260+
* @param channel the channel.
261+
* @param pattern the pattern.
262+
* @return Long array-reply list of keys matching {@code pattern}.
263+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
264+
* @deprecated since 6.0 in favor of consuming large results through the {@link org.reactivestreams.Publisher} returned by
265+
* {@link #keysLegacy}.
266+
*/
267+
@Deprecated
268+
Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern);
246269

247270
/**
248271
* Atomically transfer a key from a Redis instance to another one.

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,41 @@ public interface RedisKeyCommands<K, V> {
226226
/**
227227
* Find all keys matching the given pattern.
228228
*
229+
* @param pattern the pattern type.
230+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
231+
*/
232+
List<K> keys(String pattern);
233+
234+
/**
235+
* Find all keys matching the given pattern (legacy overload).
236+
*
229237
* @param pattern the pattern type: patternkey (pattern).
230238
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
239+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
231240
*/
232-
List<K> keys(K pattern);
241+
@Deprecated
242+
List<K> keysLegacy(K pattern);
233243

234244
/**
235245
* Find all keys matching the given pattern.
236246
*
237247
* @param channel the channel.
248+
* @param pattern the pattern type.
249+
* @return Long array-reply list of keys matching {@code pattern}.
250+
*/
251+
Long keys(KeyStreamingChannel<K> channel, String pattern);
252+
253+
/**
254+
* Find all keys matching the given pattern (legacy overload).
255+
*
256+
* @param channel the channel.
238257
* @param pattern the pattern.
239258
* @return Long array-reply list of keys matching {@code pattern}.
259+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
260+
* version.
240261
*/
241-
Long keys(KeyStreamingChannel<K> channel, K pattern);
262+
@Deprecated
263+
Long keysLegacy(KeyStreamingChannel<K> channel, K pattern);
242264

243265
/**
244266
* Atomically transfer a key from a Redis instance to another one.

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public RedisFuture<String> flushdb(FlushMode flushMode) {
296296
}
297297

298298
@Override
299-
public RedisFuture<List<K>> keys(K pattern) {
299+
public RedisFuture<List<K>> keys(String pattern) {
300300

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

@@ -309,13 +309,52 @@ public RedisFuture<List<K>> keys(K pattern) {
309309
});
310310
}
311311

312+
/**
313+
* Find all keys matching the given pattern (legacy overload).
314+
*
315+
* @param pattern the pattern type: patternkey (pattern).
316+
* @return List&lt;K&gt; array-reply list of keys matching {@code pattern}.
317+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
318+
*/
319+
@Deprecated
312320
@Override
313-
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
321+
public RedisFuture<List<K>> keysLegacy(K pattern) {
322+
323+
Map<String, CompletableFuture<List<K>>> executions = executeOnUpstream(commands -> commands.keysLegacy(pattern));
324+
325+
return new PipelinedRedisFuture<>(executions, objectPipelinedRedisFuture -> {
326+
List<K> result = new ArrayList<>();
327+
for (CompletableFuture<List<K>> future : executions.values()) {
328+
result.addAll(MultiNodeExecution.execute(future::get));
329+
}
330+
return result;
331+
});
332+
}
333+
334+
@Override
335+
public RedisFuture<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
314336

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

341+
/**
342+
* Find all keys matching the given pattern (legacy overload).
343+
*
344+
* @param channel the channel.
345+
* @param pattern the pattern.
346+
* @return Long array-reply list of keys matching {@code pattern}.
347+
* @deprecated Use {@link #keys(KeyStreamingChannel, String)} instead. This legacy overload will be removed in a later
348+
* version.
349+
*/
350+
@Deprecated
351+
@Override
352+
public RedisFuture<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
353+
354+
Map<String, CompletableFuture<Long>> executions = executeOnUpstream(commands -> commands.keysLegacy(channel, pattern));
355+
return MultiNodeExecution.aggregateAsync(executions);
356+
}
357+
319358
@Override
320359
public RedisFuture<List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys) {
321360
Map<Integer, List<K>> partitioned = SlotHash.partition(codec, Arrays.asList(keys));

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,50 @@ public Mono<String> flushdb(FlushMode flushMode) {
293293
}
294294

295295
@Override
296-
public Flux<K> keys(K pattern) {
296+
public Flux<K> keys(String pattern) {
297297

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

302+
/**
303+
* Find all keys matching the given pattern (legacy overload).
304+
*
305+
* @param pattern the pattern type: patternkey (pattern).
306+
* @return K array-reply list of keys matching {@code pattern}.
307+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
308+
*/
309+
@Deprecated
310+
@Override
311+
public Flux<K> keysLegacy(K pattern) {
312+
313+
Map<String, Publisher<K>> publishers = executeOnUpstream(commands -> commands.keysLegacy(pattern));
314+
return Flux.merge(publishers.values());
315+
}
316+
302317
@Override
303-
public Mono<Long> keys(KeyStreamingChannel<K> channel, K pattern) {
318+
public Mono<Long> keys(KeyStreamingChannel<K> channel, String pattern) {
304319

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

324+
/**
325+
* Find all keys matching the given pattern (legacy overload).
326+
*
327+
* @param channel the channel.
328+
* @param pattern the pattern.
329+
* @return Long array-reply list of keys matching {@code pattern}.
330+
* @deprecated Use {@link #keys(String)} instead. This legacy overload will be removed in a later version.
331+
*/
332+
@Deprecated
333+
@Override
334+
public Mono<Long> keysLegacy(KeyStreamingChannel<K> channel, K pattern) {
335+
336+
Map<String, Publisher<Long>> publishers = executeOnUpstream(commands -> commands.keysLegacy(channel, pattern));
337+
return Flux.merge(publishers.values()).reduce((accu, next) -> accu + next);
338+
}
339+
309340
@Override
310341
public Flux<KeyValue<K, V>> mget(K... keys) {
311342
return mget(Arrays.asList(keys));

0 commit comments

Comments
 (0)