Skip to content

Commit 6d4522a

Browse files
denglimingclaude
andcommitted
Redis 8 compatibility for FT.INFO and FT.CONFIG, fail-at-end CI build
CI now runs again and the redis-stack edge image is Redis 8, which exposed two incompatibilities: - FT.INFO replies nest attributes several levels deep; the decoder chain only covered three levels and threw ArrayIndexOutOfBounds. It now decodes up to eight levels. - FT.CONFIG was removed in Redis 8 in favour of CONFIG GET/SET search-*. setConfig()/getConfig() still try FT.CONFIG first and fall back to CONFIG when the server reports an unknown command; ConfigOption carries the Redis 8 parameter name and getConfig() reports values under the FT.CONFIG keyword so callers see the same shape on both versions. RedissonAdapter.recover() implements the fallback generically. The build workflow runs Maven with --fail-at-end so every module reports instead of stopping at the first failing one. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5e206e3 commit 6d4522a

5 files changed

Lines changed: 81 additions & 14 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
java-version: 8
5858
cache: maven
5959
- name: Build with Maven
60-
run: mvn clean install -DREDIS_HOST=localhost -DREDIS_PORT=52567 -DREDISAI_PORT=52568 -DREDIS_GEARS_PORT=6383 -DREDIS_GRAPH_PORT=6384 -Dgpg.skip --file pom.xml
60+
run: mvn --fail-at-end clean install -DREDIS_HOST=localhost -DREDIS_PORT=52567 -DREDISAI_PORT=52568 -DREDIS_GEARS_PORT=6383 -DREDIS_GRAPH_PORT=6384 -Dgpg.skip --file pom.xml
6161
- uses: codecov/codecov-action@v4
6262
with:
6363
token: ${{ secrets.CODECOV_TOKEN }}

‎commons/src/main/java/io/github/dengliming/redismodule/common/RedissonAdapter.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
import org.redisson.misc.CompletableFutureWrapper;
2626

2727
import java.util.concurrent.CompletableFuture;
28+
import java.util.concurrent.CompletionException;
2829
import java.util.concurrent.CompletionStage;
2930
import java.util.function.Function;
31+
import java.util.function.Predicate;
32+
import java.util.function.Supplier;
3033

3134
/**
3235
* Single point of contact with Redisson internals that are not part of its public API.
@@ -76,6 +79,35 @@ public static <T, R> RFuture<R> transform(RFuture<T> future, Function<? super T,
7679
return toRFuture(source.thenApply(mapper));
7780
}
7881

82+
/**
83+
* Completes with the result of {@code future}; if it fails with an error matching {@code when}, completes with
84+
* the result of {@code fallback} instead. Any other error is propagated unchanged.
85+
*/
86+
public static <T> RFuture<T> recover(RFuture<T> future, Predicate<Throwable> when,
87+
Supplier<? extends CompletionStage<T>> fallback) {
88+
CompletableFuture<T> source = future.toCompletableFuture();
89+
CompletableFuture<T> result = new CompletableFuture<>();
90+
source.whenComplete((value, error) -> {
91+
if (error == null) {
92+
result.complete(value);
93+
return;
94+
}
95+
Throwable cause = error instanceof CompletionException && error.getCause() != null ? error.getCause() : error;
96+
if (!when.test(cause)) {
97+
result.completeExceptionally(cause);
98+
return;
99+
}
100+
fallback.get().whenComplete((fallbackValue, fallbackError) -> {
101+
if (fallbackError != null) {
102+
result.completeExceptionally(fallbackError);
103+
} else {
104+
result.complete(fallbackValue);
105+
}
106+
});
107+
});
108+
return toRFuture(result);
109+
}
110+
79111
/**
80112
* Chains an asynchronous continuation onto the result of a future.
81113
*/

‎redisearch/src/main/java/io/github/dengliming/redismodule/redisearch/RediSearch.java‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.github.dengliming.redismodule.redisearch;
1818

19+
import io.github.dengliming.redismodule.common.RedissonAdapter;
1920
import io.github.dengliming.redismodule.common.util.ArgsUtil;
2021
import io.github.dengliming.redismodule.common.util.RAssert;
2122
import io.github.dengliming.redismodule.redisearch.aggregate.AggregateOptions;
@@ -49,7 +50,9 @@
4950

5051
import java.util.ArrayList;
5152
import java.util.Arrays;
53+
import java.util.HashMap;
5254
import java.util.List;
55+
import java.util.Locale;
5356
import java.util.Map;
5457

5558
import static io.github.dengliming.redismodule.redisearch.protocol.RedisCommands.FT_ADD;
@@ -376,7 +379,13 @@ public RFuture<Boolean> setConfigAsync(ConfigOption option, String value) {
376379
RAssert.notNull(option, "ConfigOption must be not null");
377380
RAssert.notNull(value, "value must be not null");
378381

379-
return commandExecutor.writeAsync(getName(), codec, FT_CONFIG_SET, option.getKeyword(), value);
382+
RFuture<Boolean> legacy = commandExecutor.writeAsync(getName(), codec, FT_CONFIG_SET, option.getKeyword(), value);
383+
// Redis 8 removed FT.CONFIG in favour of CONFIG SET search-*
384+
return RedissonAdapter.recover(legacy, RediSearch::isUnknownCommand, () -> {
385+
RFuture<Void> modern = commandExecutor.writeAsync(getName(), codec,
386+
org.redisson.client.protocol.RedisCommands.CONFIG_SET, option.getConfigParameter(), value);
387+
return RedissonAdapter.transform(modern, v -> Boolean.TRUE);
388+
});
380389
}
381390

382391
public Map<String, String> getConfig(ConfigOption option) {
@@ -386,7 +395,17 @@ public Map<String, String> getConfig(ConfigOption option) {
386395
public RFuture<Map<String, String>> getConfigAsync(ConfigOption option) {
387396
RAssert.notNull(option, "ConfigOption must be not null");
388397

389-
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, FT_CONFIG_GET, option.getKeyword());
398+
RFuture<Map<String, String>> legacy = commandExecutor.readAsync(getName(), StringCodec.INSTANCE, FT_CONFIG_GET, option.getKeyword());
399+
// Redis 8 removed FT.CONFIG in favour of CONFIG GET search-*; report the value under the FT.CONFIG keyword
400+
return RedissonAdapter.recover(legacy, RediSearch::isUnknownCommand, () -> {
401+
RFuture<Map<String, String>> modern = commandExecutor.readAsync(getName(), StringCodec.INSTANCE,
402+
org.redisson.client.protocol.RedisCommands.CONFIG_GET_MAP, option.getConfigParameter());
403+
return RedissonAdapter.transform(modern, values -> {
404+
Map<String, String> result = new HashMap<>();
405+
values.forEach((k, v) -> result.put(option.getKeyword(), v));
406+
return result;
407+
});
408+
});
390409
}
391410

392411
public Map<String, String> getHelp(ConfigOption option) {
@@ -689,6 +708,11 @@ public RFuture<List<String>> listIndexesAsync() {
689708
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, FT_LIST);
690709
}
691710

711+
private static boolean isUnknownCommand(Throwable error) {
712+
String message = error.getMessage();
713+
return message != null && message.toLowerCase(Locale.ROOT).contains("unknown command");
714+
}
715+
692716
private void checkQueryArgument(String query) {
693717
RAssert.notNull(query, "query must be not null");
694718
}
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 dengliming.
2+
* Copyright 2020-2024 dengliming.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,23 +17,32 @@
1717
package io.github.dengliming.redismodule.redisearch.index;
1818

1919
/**
20-
* @author dengliming
20+
* RediSearch runtime configuration options.
21+
* <p>
22+
* {@link #getKeyword()} is the FT.CONFIG name used up to RediSearch 2.x; {@link #getConfigParameter()} is the
23+
* {@code CONFIG GET/SET} parameter that replaces it from Redis 8 on, where FT.CONFIG no longer exists.
2124
*/
2225
public enum ConfigOption {
23-
NOGC("NOGC"),
24-
MINPREFIX("MINPREFIX"),
25-
MAXEXPANSIONS("MAXEXPANSIONS"),
26-
TIMEOUT("TIMEOUT"),
27-
ON_TIMEOUT("ON_TIMEOUT"),
28-
MIN_PHONETIC_TERM_LEN("MIN_PHONETIC_TERM_LEN");
26+
NOGC("NOGC", "search-no-gc"),
27+
MINPREFIX("MINPREFIX", "search-min-prefix"),
28+
MAXEXPANSIONS("MAXEXPANSIONS", "search-max-prefix-expansions"),
29+
TIMEOUT("TIMEOUT", "search-timeout"),
30+
ON_TIMEOUT("ON_TIMEOUT", "search-on-timeout"),
31+
MIN_PHONETIC_TERM_LEN("MIN_PHONETIC_TERM_LEN", "search-min-phonetic-term-len");
2932

30-
private String keyword;
33+
private final String keyword;
34+
private final String configParameter;
3135

32-
ConfigOption(String keyword) {
36+
ConfigOption(String keyword, String configParameter) {
3337
this.keyword = keyword;
38+
this.configParameter = configParameter;
3439
}
3540

3641
public String getKeyword() {
3742
return keyword;
3843
}
44+
45+
public String getConfigParameter() {
46+
return configParameter;
47+
}
3948
}

‎redisearch/src/main/java/io/github/dengliming/redismodule/redisearch/protocol/RedisCommands.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public interface RedisCommands {
5050
RedisCommand<Boolean> FT_ALIASADD = new RedisCommand<>("FT.ALIASADD", new BooleanReplayConvertor());
5151
RedisCommand<Boolean> FT_ALIASUPDATE = new RedisCommand<>("FT.ALIASUPDATE", new BooleanReplayConvertor());
5252
RedisCommand<Boolean> FT_ALIASDEL = new RedisCommand<>("FT.ALIASDEL", new BooleanReplayConvertor());
53-
RedisCommand<Map<String, Object>> FT_INFO = new RedisCommand<>("FT.INFO", new ListMultiDecoder2(new StringMapInfoDecoder(), new CodecDecoder(), new CodecDecoder()));
53+
// Redis 8 replies nest attributes and index options several levels deep; one CodecDecoder per level
54+
RedisCommand<Map<String, Object>> FT_INFO = new RedisCommand<>("FT.INFO", new ListMultiDecoder2(new StringMapInfoDecoder(),
55+
new CodecDecoder(), new CodecDecoder(), new CodecDecoder(), new CodecDecoder(), new CodecDecoder(), new CodecDecoder(), new CodecDecoder()));
5456
RedisCommand<AggregateResult> FT_AGGREGATE = new RedisCommand<>("FT.AGGREGATE", new ListMultiDecoder2(new AggregateDecoder(), new ObjectMapReplayDecoder()));
5557
RedisCommand<String> FT_EXPLAIN = new RedisCommand<>("FT.EXPLAIN");
5658
RedisCommand<List<String>> FT_EXPLAINCLI = new RedisCommand<>("FT.EXPLAINCLI", new ObjectListReplayDecoder<>());

0 commit comments

Comments
 (0)