Skip to content

Commit

Permalink
Java: FT._LIST. (#2568)
Browse files Browse the repository at this point in the history
Java: Add command `FT._LIST`.

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored Nov 7, 2024
1 parent b7e9d10 commit ebc9af3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* Node: Added `JSON.TYPE` ([#2510](https://github.com/valkey-io/valkey-glide/pull/2510))
* Java: Added `JSON.RESP` ([#2513](https://github.com/valkey-io/valkey-glide/pull/2513))
* Java: Added `JSON.TYPE` ([#2525](https://github.com/valkey-io/valkey-glide/pull/2525))
* Java: Added `FT._LIST` ([#2568](https://github.com/valkey-io/valkey-glide/pull/2568))
* Node: Added `FT.DROPINDEX` ([#2516](https://github.com/valkey-io/valkey-glide/pull/2516))
* Node: Added `JSON.RESP` ([#2517](https://github.com/valkey-io/valkey-glide/pull/2517))
* Node: Added `JSON.CLEAR` ([#2566](https://github.com/valkey-io/valkey-glide/pull/2566))
Expand Down
17 changes: 17 additions & 0 deletions java/client/src/main/java/glide/api/commands/servermodules/FT.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ public static CompletableFuture<Object[]> profile(
/**
* Returns information about a given index.
*
* @param client The client to execute the command.
* @param indexName The index name.
* @return Nested maps with info about the index. See example for more details.
* @example
Expand Down Expand Up @@ -587,6 +588,7 @@ public static CompletableFuture<Map<String, Object>> info(
/**
* Returns information about a given index.
*
* @param client The client to execute the command.
* @param indexName The index name.
* @return Nested maps with info about the index. See example for more details.
* @example
Expand Down Expand Up @@ -652,6 +654,21 @@ public static CompletableFuture<Map<String, Object>> info(
.collect(Collectors.toMap(e -> e.getKey().toString(), Map.Entry::getValue)));
}

/**
* Lists all indexes.
*
* @param client The client to execute the command.
* @return An array of index names.
* @example
* <pre>{@code
* GlideString[] indices = FT.list(client).get();
* }</pre>
*/
public static CompletableFuture<GlideString[]> list(@NonNull BaseClient client) {
return FT.<Object[]>executeCommand(client, new GlideString[] {gs("FT._LIST")}, false)
.thenApply(arr -> castArray(arr, GlideString.class));
}

/**
* Adds an alias for an index. The new alias name can be used anywhere that an index name is
* required.
Expand Down
14 changes: 4 additions & 10 deletions java/integTest/src/test/java/glide/modules/VectorSearchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ public void ft_search() {

@SneakyThrows
@Test
public void ft_drop() {
var index = UUID.randomUUID().toString();
public void ft_drop_and_ft_list() {
var index = gs(UUID.randomUUID().toString());
assertEquals(
OK,
FT.create(
Expand All @@ -331,17 +331,11 @@ public void ft_drop() {
})
.get());

// TODO use FT.LIST with it is done
var before =
Set.of((Object[]) client.customCommand(new String[] {"FT._LIST"}).get().getSingleValue());
var before = Set.of(FT.list(client).get());

assertEquals(OK, FT.dropindex(client, index).get());

// TODO use FT.LIST with it is done
var after =
new HashSet<>(
Set.of(
(Object[]) client.customCommand(new String[] {"FT._LIST"}).get().getSingleValue()));
var after = new HashSet<>(Set.of(FT.list(client).get()));

assertFalse(after.contains(index));
after.add(index);
Expand Down

0 comments on commit ebc9af3

Please sign in to comment.