Skip to content
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

Node: FT.INFO #2540

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Java: Added `FT.PROFILE` ([#2473](https://github.com/valkey-io/valkey-glide/pull/2473))
* Java: Added `JSON.SET` and `JSON.GET` ([#2462](https://github.com/valkey-io/valkey-glide/pull/2462))
* Node: Added `FT.CREATE` ([#2501](https://github.com/valkey-io/valkey-glide/pull/2501))
* Node: Added `FT.INFO` ([#2540](https://github.com/valkey-io/valkey-glide/pull/2540))
* Java: Added `JSON.DEBUG` ([#2520](https://github.com/valkey-io/valkey-glide/pull/2520))
* Java: Added `JSON.ARRINSERT` and `JSON.ARRLEN` ([#2476](https://github.com/valkey-io/valkey-glide/pull/2476))
* Java: Added `JSON.ARRPOP` ([#2486](https://github.com/valkey-io/valkey-glide/pull/2486))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public static CompletableFuture<Object[]> profile(
* Map<String, Object> response = client.ftinfo("myIndex").get();
* // the response contains data in the following format:
* Map<String, Object> data = Map.of(
* "index_name", gs("bcd97d68-4180-4bc5-98fe-5125d0abbcb8"),
* "index_name", gs("myIndex"),
* "index_status", gs("AVAILABLE"),
* "key_type", gs("JSON"),
* "creation_timestamp", 1728348101728771L,
Expand All @@ -566,7 +566,7 @@ public static CompletableFuture<Object[]> profile(
* gs("dimension", 6L,
* gs("block_size", 1024L,
* gs("algorithm", gs("FLAT")
* )
* )
* ),
* Map.of(
* gs("identifier"), gs("name"),
Expand Down Expand Up @@ -599,7 +599,7 @@ public static CompletableFuture<Map<String, Object>> info(
* Map<String, Object> response = client.ftinfo(gs("myIndex")).get();
* // the response contains data in the following format:
* Map<String, Object> data = Map.of(
* "index_name", gs("bcd97d68-4180-4bc5-98fe-5125d0abbcb8"),
* "index_name", gs("myIndex"),
* "index_status", gs("AVAILABLE"),
* "key_type", gs("JSON"),
* "creation_timestamp", 1728348101728771L,
Expand All @@ -625,7 +625,7 @@ public static CompletableFuture<Map<String, Object>> info(
* gs("dimension", 6L,
* gs("block_size", 1024L,
* gs("algorithm", gs("FLAT")
* )
* )
* ),
* Map.of(
* gs("identifier"), gs("name"),
Expand Down
2 changes: 2 additions & 0 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function initialize() {
VectorFieldAttributesFlat,
VectorFieldAttributesHnsw,
FtCreateOptions,
FtInfoReturnType,
GlideRecord,
GlideString,
JsonGetOptions,
Expand Down Expand Up @@ -244,6 +245,7 @@ function initialize() {
VectorFieldAttributesFlat,
VectorFieldAttributesHnsw,
FtCreateOptions,
FtInfoReturnType,
GlideRecord,
GlideJson,
GlideString,
Expand Down
3 changes: 0 additions & 3 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5510,7 +5510,6 @@ export class BaseClient {
* attributes of a consumer group for the stream at `key`.
* @example
* ```typescript
* <pre>{@code
* const result = await client.xinfoGroups("my_stream");
* console.log(result); // Output:
* // [
Expand Down Expand Up @@ -5963,13 +5962,11 @@ export class BaseClient {
*
* @example
* ```typescript
* <pre>{@code
* const entryId = await client.xadd("mystream", ["myfield", "mydata"]);
* // read messages from streamId
* const readResult = await client.xreadgroup(["myfield", "mydata"], "mygroup", "my0consumer");
* // acknowledge messages on stream
* console.log(await client.xack("mystream", "mygroup", [entryId])); // Output: 1
* </pre>
* ```
*/
public async xack(
Expand Down
92 changes: 87 additions & 5 deletions node/src/server-modules/GlideFt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { Decoder, DecoderOption, GlideString } from "../BaseClient";
import {
convertGlideRecordToRecord,
Decoder,
DecoderOption,
GlideRecord,
GlideReturnType,
GlideString,
} from "../BaseClient";
import { GlideClient } from "../GlideClient";
import { GlideClusterClient } from "../GlideClusterClient";
import { Field, FtCreateOptions } from "./GlideFtOptions";

/** Module for Vector Search commands */
/** Data type of {@link GlideFt.info | info} command response. */
type FtInfoReturnType = Record<
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
string,
| GlideString
| number
| GlideString[]
| Record<string, GlideString | Record<string, GlideString | number>[]>
>;

/** Module for Vector Search commands. */
export class GlideFt {
/**
* Creates an index and initiates a backfill of that index.
Expand Down Expand Up @@ -187,16 +203,82 @@ export class GlideFt {
decoder: Decoder.String,
}) as Promise<"OK">;
}

/**
* Returns information about a given index.
*
* @param client - The client to execute the command.
* @param indexName - The index name.
* @param options - (Optional) See {@link DecoderOption}.
*
* @returns Nested maps with info about the index. See example for more details.
*
* @example
* ```typescript
* const info = await GlideFt.info(client, "myIndex");
* console.log(info); // Output:
* // {
* // index_name: 'myIndex',
* // index_status: 'AVAILABLE',
* // key_type: 'JSON',
* // creation_timestamp: 1728348101728771,
* // key_prefixes: [ 'json:' ],
* // num_indexed_vectors: 0,
* // space_usage: 653471,
* // num_docs: 0,
* // vector_space_usage: 653471,
* // index_degradation_percentage: 0,
* // fulltext_space_usage: 0,
* // current_lag: 0,
* // fields: [
* // {
* // identifier: '$.vec',
* // type: 'VECTOR',
* // field_name: 'VEC',
* // option: '',
* // vector_params: {
* // data_type: 'FLOAT32',
* // initial_capacity: 1000,
* // current_capacity: 1000,
* // distance_metric: 'L2',
* // dimension: 6,
* // block_size: 1024,
* // algorithm: 'FLAT'
* // }
* // },
* // {
* // identifier: 'name',
* // type: 'TEXT',
* // field_name: 'name',
* // option: ''
* // },
* // ]
* // }
* ```
*/
static async info(
client: GlideClient | GlideClusterClient,
indexName: GlideString,
options?: DecoderOption,
): Promise<FtInfoReturnType> {
const args: GlideString[] = ["FT.INFO", indexName];

return (
_handleCustomCommand(client, args, options) as Promise<
GlideRecord<GlideString>
>
).then(convertGlideRecordToRecord);
acarbonetto marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* @internal
*/
function _handleCustomCommand(
async function _handleCustomCommand(
client: GlideClient | GlideClusterClient,
args: GlideString[],
decoderOption: DecoderOption,
) {
decoderOption?: DecoderOption,
): Promise<GlideReturnType> {
return client instanceof GlideClient
? (client as GlideClient).customCommand(args, decoderOption)
: (client as GlideClusterClient).customCommand(args, decoderOption);
Expand Down
Loading
Loading