Skip to content

Commit

Permalink
Introducing the FT.CREATE command
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Feb 2, 2025
1 parent ee7c46c commit b6d6d4a
Show file tree
Hide file tree
Showing 23 changed files with 1,769 additions and 11 deletions.
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.Fields;
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, Fields<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.Fields;
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, Fields<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
62 changes: 62 additions & 0 deletions src/main/java/io/lettuce/core/RediSearchCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.Fields;
import io.lettuce.core.search.arguments.CreateArgs;
import io.lettuce.core.search.Field;

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, Fields<K> fields) {
notNullKey(index);
notEmpty(fields.getFields().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.getFields()) {
field.build(args);
}

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

}

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

import io.lettuce.core.RedisFuture;
import io.lettuce.core.search.Fields;
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
* @param options the index options
* @param fields the fields
* @return the result of the create command
*/
RedisFuture<String> ftCreate(K index, CreateArgs<K, V> options, Fields<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,36 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.reactive;

import io.lettuce.core.search.Field;
import io.lettuce.core.search.Fields;
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
* @param options the index options
* @param fields the fields
* @return the result of the create command
*/
Mono<String> ftCreate(K index, CreateArgs<K, V> options, Fields<K> fields);

}
34 changes: 34 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,34 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.api.sync;

import io.lettuce.core.search.Fields;
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
* @param options the index options
* @param fields the fields
* @return the result of the create command
*/
String ftCreate(K index, CreateArgs<K, V> options, Fields<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,34 @@
/*
* Copyright 2025, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*/
package io.lettuce.core.cluster.api.async;

import io.lettuce.core.search.Fields;
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
* @param options the index options
* @param fields the fields
* @return the result of the create command
*/
AsyncExecutions<String> ftCreate(K index, CreateArgs<K, V> options, Fields<K> fields);

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

import io.lettuce.core.search.Field;
import io.lettuce.core.search.Fields;
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
* @param options the index options
* @param fields the fields
* @return the result of the create command
*/
Executions<String> ftCreate(K index, CreateArgs<K, V> options, Fields<K> fields);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @param <V> Value type.
* @author Mark Paluch
* @author dengliming
* @author Tihomir Mateev
* @since 4.0
*/
public interface RedisClusterCommands<K, V>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public enum CommandKeyword implements ProtocolKeyword {

MIGRATING, IMPORTING, SAVE, SKIPME, SLAVES, STREAM, STORE, SUM, SEGFAULT, SETUSER, TAKEOVER, TRACKING, TRACKINGINFO, TYPE, UNBLOCK, USERS, USAGE, WEIGHTS, WHOAMI,

WITHMATCHLEN, WITHSCORE, WITHSCORES, WITHVALUES, XOR, XX, YES, INDENT, NEWLINE, SPACE, GT, LT;
WITHMATCHLEN, WITHSCORE, WITHSCORES, WITHVALUES, XOR, XX, YES, INDENT, NEWLINE, SPACE, GT, LT,

MAXTEXTFIELDS, PREFIX, FILTER, LANGUAGE, LANGUAGE_FIELD, SCORE, SCORE_FIELD, PAYLOAD_FIELD, TEMPORARY, NOOFFSETS, NOHL, NOFIELDS, NOFREQS, SKIPINITIALSCAN, STOPWORDS, AS, SORTABLE, SCHEMA, UNF, NOINDEX,

NOSTEM, PHONETIC, WEIGHT, SEPARATOR, CASESENSITIVE, WITHSUFFIXTRIE, INDEXEMPTY, INDEXMISSING;

public final byte[] bytes;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public enum CommandType implements ProtocolKeyword {
"JSON.OBJLEN"), JSON_SET("JSON.SET"), JSON_STRAPPEND("JSON.STRAPPEND"), JSON_STRLEN(
"JSON.STRLEN"), JSON_TOGGLE("JSON.TOGGLE"), JSON_TYPE("JSON.TYPE"),

// RediSearch
FT_CREATE("FT.CREATE"),

// Others

TIME, WAIT,
Expand Down
Loading

0 comments on commit b6d6d4a

Please sign in to comment.