Skip to content

Add support for FT.CREATE #2717 #3150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
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
13 changes: 12 additions & 1 deletion src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.ProtocolKeyword;
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import reactor.core.publisher.Mono;

import java.time.Duration;
Expand Down Expand Up @@ -79,14 +81,17 @@ public abstract class AbstractRedisAsyncCommands<K, V> implements RedisAclAsyncC
RedisKeyAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>, RedisListAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
RedisSortedSetAsyncCommands<K, V>, RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>,
RedisHLLAsyncCommands<K, V>, BaseRedisAsyncCommands<K, V>, RedisTransactionalAsyncCommands<K, V>,
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>,
RediSearchAsyncCommands<K, V> {

private final StatefulConnection<K, V> connection;

private final RedisCommandBuilder<K, V> commandBuilder;

private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;

private final RediSearchCommandBuilder<K, V> searchCommandBuilder;

private final Mono<JsonParser> parser;

/**
Expand All @@ -101,6 +106,7 @@ public AbstractRedisAsyncCommands(StatefulConnection<K, V> connection, RedisCode
this.connection = connection;
this.commandBuilder = new RedisCommandBuilder<>(codec);
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
}

/**
Expand Down Expand Up @@ -1478,6 +1484,11 @@ public boolean isOpen() {
return connection.isOpen();
}

@Override
public RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
return dispatch(searchCommandBuilder.ftCreate(index, options, fields));
}

@Override
public RedisFuture<List<Long>> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
return dispatch(jsonCommandBuilder.jsonArrappend(key, jsonPath, values));
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.protocol.TracedCommand;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import io.lettuce.core.tracing.TraceContext;
import io.lettuce.core.tracing.TraceContextProvider;
import io.lettuce.core.tracing.Tracing;
Expand Down Expand Up @@ -84,19 +86,21 @@
* @author Tihomir Mateev
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V>
implements RedisAclReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
RedisStringReactiveCommands<K, V>, RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
RedisSortedSetReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
RedisHLLReactiveCommands<K, V>, BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>,
RedisGeoReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisAclReactiveCommands<K, V>,
RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>,
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>,
BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
RedisClusterReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {

private final StatefulConnection<K, V> connection;

private final RedisCommandBuilder<K, V> commandBuilder;

private final RedisJsonCommandBuilder<K, V> jsonCommandBuilder;

private final RediSearchCommandBuilder<K, V> searchCommandBuilder;

private final Mono<JsonParser> parser;

private final ClientResources clientResources;
Expand All @@ -117,6 +121,7 @@ public AbstractRedisReactiveCommands(StatefulConnection<K, V> connection, RedisC
this.parser = parser;
this.commandBuilder = new RedisCommandBuilder<>(codec);
this.jsonCommandBuilder = new RedisJsonCommandBuilder<>(codec, parser);
this.searchCommandBuilder = new RediSearchCommandBuilder<>(codec);
this.clientResources = connection.getResources();
this.tracingEnabled = clientResources.tracing().isEnabled();
}
Expand Down Expand Up @@ -1543,6 +1548,11 @@ public boolean isOpen() {
return connection.isOpen();
}

@Override
public Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields) {
return createMono(() -> searchCommandBuilder.ftCreate(index, options, fields));
}

@Override
public Flux<Long> jsonArrappend(K key, JsonPath jsonPath, JsonValue... values) {
return createDissolvingFlux(() -> jsonCommandBuilder.jsonArrappend(key, jsonPath, values));
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/io/lettuce/core/RediSearchCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core;

import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.BaseRedisCommandBuilder;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;
import io.lettuce.core.search.arguments.CreateArgs;
import io.lettuce.core.search.Field;

import java.util.List;

import static io.lettuce.core.protocol.CommandType.*;

/**
* Command builder for RediSearch commands.
*
* @param <K> Key type.
* @param <V> Value type.
* @since 6.6
*/
class RediSearchCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {

RediSearchCommandBuilder(RedisCodec<K, V> codec) {
super(codec);
}

/**
* Create a new index with the given name, index options and fields.
*
* @param index the index name
* @param createArgs the index options
* @param fields the fields
* @return the result of the create command
*/
public Command<K, V, String> ftCreate(K index, CreateArgs<K, V> createArgs, List<Field<K>> fields) {
notNullKey(index);
notEmpty(fields.toArray());

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(index);

if (createArgs != null) {
createArgs.build(args);
}

args.add(CommandKeyword.SCHEMA);

for (Field<K> field : fields) {
field.build(args);
}

return createCommand(FT_CREATE, new StatusOutput<>(codec), args);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.async;

import java.util.List;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;

/**
* Asynchronous executed commands for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateAsyncApi
*/
public interface RediSearchAsyncCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface RedisAsyncCommands<K, V> extends BaseRedisAsyncCommands<K, V>,
RedisHashAsyncCommands<K, V>, RedisHLLAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>, RedisListAsyncCommands<K, V>,
RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
RedisSortedSetAsyncCommands<K, V>, RedisStreamAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>,
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V> {
RedisTransactionalAsyncCommands<K, V>, RedisJsonAsyncCommands<K, V>, RediSearchAsyncCommands<K, V> {

/**
* Authenticate to the server.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.reactive;

import java.util.List;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;
import reactor.core.publisher.Mono;

/**
* Reactive executed commands for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateReactiveApi
*/
public interface RediSearchReactiveCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
Mono<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
* @author Mark Paluch
* @since 5.0
*/
public interface RedisReactiveCommands<K, V> extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>,
RedisClusterReactiveCommands<K, V>, RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
RedisHashReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>,
RedisListReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>,
RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>,
RedisStringReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V> {
public interface RedisReactiveCommands<K, V>
extends BaseRedisReactiveCommands<K, V>, RedisAclReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V>,
RedisFunctionReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>, RedisHashReactiveCommands<K, V>,
RedisHLLReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisListReactiveCommands<K, V>,
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>,
RedisSortedSetReactiveCommands<K, V>, RedisStreamReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
RedisTransactionalReactiveCommands<K, V>, RedisJsonReactiveCommands<K, V>, RediSearchReactiveCommands<K, V> {

/**
* Authenticate to the server.
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RediSearchCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.sync;

import java.util.List;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;

/**
* Synchronous executed commands for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateSyncApi
*/
public interface RediSearchCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
String ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

}
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/api/sync/RedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface RedisCommands<K, V> extends BaseRedisCommands<K, V>, RedisAclCo
RedisFunctionCommands<K, V>, RedisGeoCommands<K, V>, RedisHashCommands<K, V>, RedisHLLCommands<K, V>,
RedisKeyCommands<K, V>, RedisListCommands<K, V>, RedisScriptingCommands<K, V>, RedisServerCommands<K, V>,
RedisSetCommands<K, V>, RedisSortedSetCommands<K, V>, RedisStreamCommands<K, V>, RedisStringCommands<K, V>,
RedisTransactionalCommands<K, V>, RedisJsonCommands<K, V> {
RedisTransactionalCommands<K, V>, RedisJsonCommands<K, V>, RediSearchCommands<K, V> {

/**
* Authenticate to the server.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.cluster.api.async;

import java.util.List;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;

/**
* Asynchronous executed commands on a node selection for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateAsyncNodeSelectionClusterApi
*/
public interface RediSearchAsyncCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
AsyncExecutions<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.cluster.api.sync;

import java.util.List;
import io.lettuce.core.search.Field;
import io.lettuce.core.search.arguments.CreateArgs;

/**
* Synchronous executed commands on a node selection for RediSearch functionality
*
* @param <K> Key type.
* @param <V> Value type.
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/search/">RediSearch</a>
* @since 6.6
* @generated by io.lettuce.apigenerator.CreateSyncNodeSelectionClusterApi
*/
public interface RediSearchCommands<K, V> {

/**
* Create a new index with the given name, index options, and fields.
*
* @param index the index name, as a key
* @param options the index {@link CreateArgs}
* @param fields the {@link Field}s of the index
* @return the result of the create command
* @since 6.6
* @see <a href="https://redis.io/docs/latest/commands/ft.create/">FT.CREATE</a>
*/
Executions<String> ftCreate(K index, CreateArgs<K, V> options, List<Field<K>> fields);

}
Loading