Skip to content

Commit fcb7a1f

Browse files
authored
Revert "Revert "Add support for FT.CREATE #2717 (#3150)" (#3160)" (#3161)
This reverts commit 319e315.
1 parent 319e315 commit fcb7a1f

23 files changed

+1764
-17
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import io.lettuce.core.protocol.CommandType;
4949
import io.lettuce.core.protocol.ProtocolKeyword;
5050
import io.lettuce.core.protocol.RedisCommand;
51+
import io.lettuce.core.search.Field;
52+
import io.lettuce.core.search.arguments.CreateArgs;
5153
import reactor.core.publisher.Mono;
5254

5355
import java.time.Duration;
@@ -79,14 +81,17 @@ public abstract class AbstractRedisAsyncCommands<K, V> implements RedisAclAsyncC
7981
RedisKeyAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>, RedisListAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
8082
RedisSortedSetAsyncCommands<K, V>, RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>,
8183
RedisHLLAsyncCommands<K, V>, BaseRedisAsyncCommands<K, V>, RedisTransactionalAsyncCommands<K, V>,
82-
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
84+
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>,
85+
RediSearchAsyncCommands<K, V> {
8386

8487
private final StatefulConnection<K, V> connection;
8588

8689
private final RedisCommandBuilder<K, V> commandBuilder;
8790

8891
private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;
8992

93+
private final RediSearchCommandBuilder<K, V> searchCommandBuilder;
94+
9095
private final Mono<JsonParser> parser;
9196

9297
/**
@@ -101,6 +106,7 @@ public AbstractRedisAsyncCommands(StatefulConnection<K, V> connection, RedisCode
101106
this.connection = connection;
102107
this.commandBuilder = new RedisCommandBuilder<>(codec);
103108
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
109+
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
104110
}
105111

106112
/**
@@ -1478,6 +1484,11 @@ public boolean isOpen() {
14781484
return connection.isOpen();
14791485
}
14801486

1487+
@Override
1488+
public RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
1489+
return dispatch(searchCommandBuilder.ftCreate(index, options, fields));
1490+
}
1491+
14811492
@Override
14821493
public RedisFuture<List<Long>> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
14831494
return dispatch(jsonCommandBuilder.jsonArrappend(key, jsonPath, values));

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import io.lettuce.core.protocol.RedisCommand;
5050
import io.lettuce.core.protocol.TracedCommand;
5151
import io.lettuce.core.resource.ClientResources;
52+
import io.lettuce.core.search.Field;
53+
import io.lettuce.core.search.arguments.CreateArgs;
5254
import io.lettuce.core.tracing.TraceContext;
5355
import io.lettuce.core.tracing.TraceContextProvider;
5456
import io.lettuce.core.tracing.Tracing;
@@ -84,19 +86,21 @@
8486
* @author Tihomir Mateev
8587
* @since 4.0
8688
*/
87-
public abstract class AbstractRedisReactiveCommands<K, V>
88-
implements RedisAclReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
89-
RedisStringReactiveCommands<K, V>, RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
90-
RedisSortedSetReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
91-
RedisHLLReactiveCommands<K, V>, BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>,
92-
RedisGeoReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
89+
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisAclReactiveCommands<K, V>,
90+
RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
91+
RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>,
92+
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>,
93+
BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
94+
RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {
9395

9496
private final StatefulConnection<K, V> connection;
9597

9698
private final RedisCommandBuilder<K, V> commandBuilder;
9799

98100
private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;
99101

102+
private final RediSearchCommandBuilder<K, V> searchCommandBuilder;
103+
100104
private final Mono<JsonParser> parser;
101105

102106
private final ClientResources clientResources;
@@ -117,6 +121,7 @@ public AbstractRedisReactiveCommands(StatefulConnection<K, V> connection, RedisC
117121
this.parser = parser;
118122
this.commandBuilder = new RedisCommandBuilder<>(codec);
119123
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
124+
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
120125
this.clientResources = connection.getResources();
121126
this.tracingEnabled = clientResources.tracing().isEnabled();
122127
}
@@ -1543,6 +1548,11 @@ public boolean isOpen() {
15431548
return connection.isOpen();
15441549
}
15451550

1551+
@Override
1552+
public Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
1553+
return createMono(() -> searchCommandBuilder.ftCreate(index, options, fields));
1554+
}
1555+
15461556
@Override
15471557
public Flux<Long> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
15481558
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrappend(key, jsonPath, values));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2025, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package io.lettuce.core;
8+
9+
import io.lettuce.core.codec.RedisCodec;
10+
import io.lettuce.core.output.StatusOutput;
11+
import io.lettuce.core.protocol.BaseRedisCommandBuilder;
12+
import io.lettuce.core.protocol.Command;
13+
import io.lettuce.core.protocol.CommandArgs;
14+
import io.lettuce.core.protocol.CommandKeyword;
15+
import io.lettuce.core.search.arguments.CreateArgs;
16+
import io.lettuce.core.search.Field;
17+
18+
import java.util.List;
19+
20+
import static io.lettuce.core.protocol.CommandType.*;
21+
22+
/**
23+
* Command builder for RediSearch commands.
24+
*
25+
* @param <K> Key type.
26+
* @param <V> Value type.
27+
* @since 6.6
28+
*/
29+
class RediSearchCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {
30+
31+
RediSearchCommandBuilder(RedisCodec<K, V> codec) {
32+
super(codec);
33+
}
34+
35+
/**
36+
* Create a new index with the given name, index options and fields.
37+
*
38+
* @param index the index name
39+
* @param createArgs the index options
40+
* @param fields the fields
41+
* @return the result of the create command
42+
*/
43+
public Command<K, V, String> ftCreate(K index, CreateArgs<K, V> createArgs, List<Field<K>> fields) {
44+
notNullKey(index);
45+
notEmpty(fields.toArray());
46+
47+
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(index);
48+
49+
if (createArgs != null) {
50+
createArgs.build(args);
51+
}
52+
53+
args.add(CommandKeyword.SCHEMA);
54+
55+
for (Field<K> field : fields) {
56+
field.build(args);
57+
}
58+
59+
return createCommand(FT_CREATE, new StatusOutput<>(codec), args);
60+
61+
}
62+
63+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package io.lettuce.core.api.async;
8+
9+
import java.util.List;
10+
import io.lettuce.core.RedisFuture;
11+
import io.lettuce.core.search.Field;
12+
import io.lettuce.core.search.arguments.CreateArgs;
13+
14+
/**
15+
* Asynchronous executed commands for RediSearch functionality
16+
*
17+
* @param <K> Key type.
18+
* @param <V> Value type.
19+
* @author Tihomir Mateev
20+
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
21+
* @since 6.6
22+
* @generated by io.lettuce.apigenerator.CreateAsyncApi
23+
*/
24+
public interface RediSearchAsyncCommands<K, V> {
25+
26+
/**
27+
* Create a new index with the given name, index options, and fields.
28+
*
29+
* @param index the index name, as a key
30+
* @param options the index {@link CreateArgs}
31+
* @param fields the {@link Field}s of the index
32+
* @return the result of the create command
33+
* @since 6.6
34+
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
35+
*/
36+
RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);
37+
38+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface RedisAsyncCommands<K, V> extends BaseRedisAsyncCommands<K, V>,
3737
RedisHashAsyncCommands<K, V>, RedisHLLAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>, RedisListAsyncCommands<K, V>,
3838
RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
3939
RedisSortedSetAsyncCommands<K, V>, RedisStreamAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>,
40-
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
40+
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>, RediSearchAsyncCommands<K, V> {
4141

4242
/**
4343
* Authenticate to the server.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package io.lettuce.core.api.reactive;
8+
9+
import java.util.List;
10+
import io.lettuce.core.search.Field;
11+
import io.lettuce.core.search.arguments.CreateArgs;
12+
import reactor.core.publisher.Mono;
13+
14+
/**
15+
* Reactive executed commands for RediSearch functionality
16+
*
17+
* @param <K> Key type.
18+
* @param <V> Value type.
19+
* @author Tihomir Mateev
20+
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
21+
* @since 6.6
22+
* @generated by io.lettuce.apigenerator.CreateReactiveApi
23+
*/
24+
public interface RediSearchReactiveCommands<K, V> {
25+
26+
/**
27+
* Create a new index with the given name, index options, and fields.
28+
*
29+
* @param index the index name, as a key
30+
* @param options the index {@link CreateArgs}
31+
* @param fields the {@link Field}s of the index
32+
* @return the result of the create command
33+
* @since 6.6
34+
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
35+
*/
36+
Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);
37+
38+
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
* @author Mark Paluch
3232
* @since 5.0
3333
*/
34-
public interface RedisReactiveCommands<K, V> extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>,
35-
RedisClusterReactiveCommands<K, V>, RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
36-
RedisHashReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
37-
RedisListReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
38-
RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>,
39-
RedisStringReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
34+
public interface RedisReactiveCommands<K, V>
35+
extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>,
36+
RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>,
37+
RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisListReactiveCommands<K, V>,
38+
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
39+
RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
40+
RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {
4041

4142
/**
4243
* Authenticate to the server.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package io.lettuce.core.api.sync;
8+
9+
import java.util.List;
10+
import io.lettuce.core.search.Field;
11+
import io.lettuce.core.search.arguments.CreateArgs;
12+
13+
/**
14+
* Synchronous executed commands for RediSearch functionality
15+
*
16+
* @param <K> Key type.
17+
* @param <V> Value type.
18+
* @author Tihomir Mateev
19+
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
20+
* @since 6.6
21+
* @generated by io.lettuce.apigenerator.CreateSyncApi
22+
*/
23+
public interface RediSearchCommands<K, V> {
24+
25+
/**
26+
* Create a new index with the given name, index options, and fields.
27+
*
28+
* @param index the index name, as a key
29+
* @param options the index {@link CreateArgs}
30+
* @param fields the {@link Field}s of the index
31+
* @return the result of the create command
32+
* @since 6.6
33+
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
34+
*/
35+
String ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);
36+
37+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface RedisCommands<K, V> extends BaseRedisCommands<K, V>, RedisAclCo
3636
RedisFunctionCommands<K, V>, RedisGeoCommands<K, V>, RedisHashCommands<K, V>, RedisHLLCommands<K, V>,
3737
RedisKeyCommands<K, V>, RedisListCommands<K, V>, RedisScriptingCommands<K, V>, RedisServerCommands<K, V>,
3838
RedisSetCommands<K, V>, RedisSortedSetCommands<K, V>, RedisStreamCommands<K, V>, RedisStringCommands<K, V>,
39-
RedisTransactionalCommands<K, V>, RedisJsonCommands<K, V> {
39+
RedisTransactionalCommands<K, V>, RedisJsonCommands<K, V>, RediSearchCommands<K, V> {
4040

4141
/**
4242
* Authenticate to the server.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*/
7+
package io.lettuce.core.cluster.api.async;
8+
9+
import java.util.List;
10+
import io.lettuce.core.search.Field;
11+
import io.lettuce.core.search.arguments.CreateArgs;
12+
13+
/**
14+
* Asynchronous executed commands on a node selection for RediSearch functionality
15+
*
16+
* @param <K> Key type.
17+
* @param <V> Value type.
18+
* @author Tihomir Mateev
19+
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
20+
* @since 6.6
21+
* @generated by io.lettuce.apigenerator.CreateAsyncNodeSelectionClusterApi
22+
*/
23+
public interface RediSearchAsyncCommands<K, V> {
24+
25+
/**
26+
* Create a new index with the given name, index options, and fields.
27+
*
28+
* @param index the index name, as a key
29+
* @param options the index {@link CreateArgs}
30+
* @param fields the {@link Field}s of the index
31+
* @return the result of the create command
32+
* @since 6.6
33+
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
34+
*/
35+
AsyncExecutions<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);
36+
37+
}

0 commit comments

Comments
 (0)