@valkey/valkey-glide 1.2.0-rc8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-ts/index.js +3 -6
- package/build-ts/src/BaseClient.d.ts +67 -0
- package/build-ts/src/GlideClient.d.ts +87 -0
- package/build-ts/src/GlideClusterClient.d.ts +268 -2
- package/build-ts/src/server-modules/GlideFt.d.ts +412 -0
- package/build-ts/src/server-modules/GlideFtOptions.d.ts +244 -0
- package/build-ts/src/server-modules/GlideJson.d.ts +829 -0
- package/package.json +9 -9
package/build-ts/index.js
CHANGED
|
@@ -65,10 +65,11 @@ function loadNativeBinding() {
|
|
|
65
65
|
}
|
|
66
66
|
function initialize() {
|
|
67
67
|
const nativeBinding = loadNativeBinding();
|
|
68
|
-
const { AggregationType, BaseScanOptions, ZScanOptions, HScanOptions, BitEncoding, BitFieldGet, BitFieldIncrBy, BitFieldOffset, BitFieldOverflow, BitFieldSet, BitFieldSubCommands, BitOffset, BitOffsetMultiplier, BitOffsetOptions, BitOverflowControl, BitmapIndexType, BitwiseOperation, ConditionalChange, Decoder, DecoderOption, GeoAddOptions, CoordOrigin, MemberOrigin, SearchOrigin, GeoBoxShape, GeoCircleShape, GeoSearchShape, GeoSearchResultOptions, GeoSearchStoreResultOptions, SortOrder, GeoUnit, GeospatialData, GlideClient, GlideClusterClient, GlideClientConfiguration, GlideJson, GlideFt, TextField, TagField, NumericField, VectorField, VectorFieldAttributesFlat, VectorFieldAttributesHnsw, FtCreateOptions, FtSearchOptions, FtInfoReturnType, FtAggregateOptions, FtAggregateLimit, FtAggregateFilter, FtAggregateGroupBy, FtAggregateReducer, FtAggregateSortBy, FtAggregateSortProperty, FtAggregateApply, FtAggregateReturnType, FtSearchReturnType,
|
|
68
|
+
const { AggregationType, BaseScanOptions, ScanOptions, ZScanOptions, HScanOptions, BitEncoding, BitFieldGet, BitFieldIncrBy, BitFieldOffset, BitFieldOverflow, BitFieldSet, BitFieldSubCommands, BitOffset, BitOffsetMultiplier, BitOffsetOptions, BitOverflowControl, BitmapIndexType, BitwiseOperation, ConditionalChange, Decoder, DecoderOption, GeoAddOptions, CoordOrigin, MemberOrigin, SearchOrigin, GeoBoxShape, GeoCircleShape, GeoSearchShape, GeoSearchResultOptions, GeoSearchStoreResultOptions, SortOrder, GeoUnit, GeospatialData, GlideClient, GlideClusterClient, GlideClientConfiguration, GlideJson, GlideFt, Field, TextField, TagField, NumericField, VectorField, VectorFieldAttributesFlat, VectorFieldAttributesHnsw, FtCreateOptions, FtSearchOptions, FtInfoReturnType, FtAggregateOptions, FtAggregateLimit, FtAggregateFilter, FtAggregateGroupBy, FtAggregateReducer, FtAggregateSortBy, FtAggregateSortProperty, FtAggregateApply, FtAggregateReturnType, FtSearchReturnType, GlideRecord, GlideString, JsonGetOptions, JsonArrPopOptions, SortedSetDataType, StreamEntryDataType, HashDataType, FunctionListOptions, FunctionListResponse, FunctionStatsSingleResponse, FunctionStatsFullResponse, FunctionRestorePolicy, SlotIdTypes, SlotKeyTypes, TimeUnit, RouteByAddress, RouteOption, Routes, RestoreOptions, SingleNodeRoute, PeriodicChecksManualInterval, PeriodicChecks, Logger, Limit, LolwutOptions, LPosOptions, ListDirection, ExpireOptions, FlushMode, InfoOptions, InsertPosition, SetOptions, ZAddOptions, InfBoundary, KeyWeight, Boundary, ProtocolVersion, RangeByIndex, RangeByScore, RangeByLex, ReadFrom, ServerCredentials, SortOptions, StreamGroupOptions, StreamTrimOptions, StreamAddOptions, StreamReadGroupOptions, StreamReadOptions, StreamClaimOptions, StreamPendingOptions, ClosingError, ConfigurationError, ExecAbortError, ValkeyError, GlideReturnType, StreamEntries, ReturnTypeXinfoStream, RequestError, TimeoutError, ConnectionError, ClusterTransaction, Transaction, PubSubMsg, ScoreFilter, SignedEncoding, UnsignedEncoding, UpdateByScore, createLeakedArray, createLeakedAttribute, createLeakedBigint, createLeakedDouble, createLeakedMap, createLeakedString, Script, ObjectType, ClusterScanCursor, BaseClientConfiguration, GlideClusterClientConfiguration, LevelOptions, ReturnTypeRecord, ReturnTypeMap, ClusterResponse, ReturnTypeAttribute, ReturnTypeJson, UniversalReturnTypeJson, } = nativeBinding;
|
|
69
69
|
module.exports = {
|
|
70
70
|
AggregationType,
|
|
71
71
|
BaseScanOptions,
|
|
72
|
+
ScanOptions,
|
|
72
73
|
HScanOptions,
|
|
73
74
|
ZScanOptions,
|
|
74
75
|
BitEncoding,
|
|
@@ -89,6 +90,7 @@ function initialize() {
|
|
|
89
90
|
DecoderOption,
|
|
90
91
|
GeoAddOptions,
|
|
91
92
|
GlideFt,
|
|
93
|
+
Field,
|
|
92
94
|
TextField,
|
|
93
95
|
TagField,
|
|
94
96
|
NumericField,
|
|
@@ -108,7 +110,6 @@ function initialize() {
|
|
|
108
110
|
FtAggregateApply,
|
|
109
111
|
FtAggregateReturnType,
|
|
110
112
|
FtSearchReturnType,
|
|
111
|
-
FtProfileOtions,
|
|
112
113
|
GlideRecord,
|
|
113
114
|
GlideJson,
|
|
114
115
|
GlideString,
|
|
@@ -162,16 +163,13 @@ function initialize() {
|
|
|
162
163
|
InfBoundary,
|
|
163
164
|
KeyWeight,
|
|
164
165
|
Boundary,
|
|
165
|
-
UpdateOptions,
|
|
166
166
|
ProtocolVersion,
|
|
167
167
|
RangeByIndex,
|
|
168
168
|
RangeByScore,
|
|
169
169
|
RangeByLex,
|
|
170
170
|
ReadFrom,
|
|
171
171
|
ServerCredentials,
|
|
172
|
-
SortClusterOptions,
|
|
173
172
|
SortOptions,
|
|
174
|
-
SortedSetRange,
|
|
175
173
|
StreamGroupOptions,
|
|
176
174
|
StreamTrimOptions,
|
|
177
175
|
StreamAddOptions,
|
|
@@ -200,7 +198,6 @@ function initialize() {
|
|
|
200
198
|
createLeakedDouble,
|
|
201
199
|
createLeakedMap,
|
|
202
200
|
createLeakedString,
|
|
203
|
-
parseInfoResponse,
|
|
204
201
|
Script,
|
|
205
202
|
ObjectType,
|
|
206
203
|
ClusterScanCursor,
|
|
@@ -142,6 +142,67 @@ export type ReadFrom =
|
|
|
142
142
|
| "AZAffinity";
|
|
143
143
|
/**
|
|
144
144
|
* Configuration settings for creating a client. Shared settings for standalone and cluster clients.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* The `BaseClientConfiguration` interface defines the foundational configuration options used when creating a client to connect to a Valkey server or cluster. It includes connection details, authentication, communication protocols, and various settings that influence the client's behavior and interaction with the server.
|
|
148
|
+
*
|
|
149
|
+
* ### Connection Details
|
|
150
|
+
*
|
|
151
|
+
* - **Addresses**: Use the `addresses` property to specify the hostnames and ports of the server(s) to connect to.
|
|
152
|
+
* - **Cluster Mode**: In cluster mode, the client will discover other nodes based on the provided addresses.
|
|
153
|
+
* - **Standalone Mode**: In standalone mode, only the provided nodes will be used.
|
|
154
|
+
*
|
|
155
|
+
* ### Security Settings
|
|
156
|
+
*
|
|
157
|
+
* - **TLS**: Enable secure communication using `useTLS`.
|
|
158
|
+
* - **Authentication**: Provide `credentials` to authenticate with the server.
|
|
159
|
+
*
|
|
160
|
+
* ### Communication Settings
|
|
161
|
+
*
|
|
162
|
+
* - **Request Timeout**: Set `requestTimeout` to specify how long the client should wait for a request to complete.
|
|
163
|
+
* - **Protocol Version**: Choose the serialization protocol using `protocol`.
|
|
164
|
+
*
|
|
165
|
+
* ### Client Identification
|
|
166
|
+
*
|
|
167
|
+
* - **Client Name**: Set `clientName` to identify the client connection.
|
|
168
|
+
*
|
|
169
|
+
* ### Read Strategy
|
|
170
|
+
*
|
|
171
|
+
* - Use `readFrom` to specify the client's read strategy (e.g., primary, preferReplica, AZAffinity).
|
|
172
|
+
*
|
|
173
|
+
* ### Availability Zone
|
|
174
|
+
*
|
|
175
|
+
* - Use `clientAz` to specify the client's availability zone, which can influence read operations when using `readFrom: 'AZAffinity'`.
|
|
176
|
+
*
|
|
177
|
+
* ### Decoder Settings
|
|
178
|
+
*
|
|
179
|
+
* - **Default Decoder**: Set `defaultDecoder` to specify how responses are decoded by default.
|
|
180
|
+
*
|
|
181
|
+
* ### Concurrency Control
|
|
182
|
+
*
|
|
183
|
+
* - **Inflight Requests Limit**: Control the number of concurrent requests using `inflightRequestsLimit`.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const config: BaseClientConfiguration = {
|
|
188
|
+
* addresses: [
|
|
189
|
+
* { host: 'redis-node-1.example.com', port: 6379 },
|
|
190
|
+
* { host: 'redis-node-2.example.com' }, // Defaults to port 6379
|
|
191
|
+
* ],
|
|
192
|
+
* useTLS: true,
|
|
193
|
+
* credentials: {
|
|
194
|
+
* username: 'myUser',
|
|
195
|
+
* password: 'myPassword',
|
|
196
|
+
* },
|
|
197
|
+
* requestTimeout: 5000, // 5 seconds
|
|
198
|
+
* protocol: ProtocolVersion.RESP3,
|
|
199
|
+
* clientName: 'myValkeyClient',
|
|
200
|
+
* readFrom: ReadFrom.AZAffinity,
|
|
201
|
+
* clientAz: 'us-east-1a',
|
|
202
|
+
* defaultDecoder: Decoder.String,
|
|
203
|
+
* inflightRequestsLimit: 1000,
|
|
204
|
+
* };
|
|
205
|
+
* ```
|
|
145
206
|
*/
|
|
146
207
|
export interface BaseClientConfiguration {
|
|
147
208
|
/**
|
|
@@ -5216,5 +5277,11 @@ export declare class BaseClient {
|
|
|
5216
5277
|
* ```
|
|
5217
5278
|
*/
|
|
5218
5279
|
updateConnectionPassword(password: string | null, immediateAuth?: boolean): Promise<GlideString>;
|
|
5280
|
+
/**
|
|
5281
|
+
* Return a statistics
|
|
5282
|
+
*
|
|
5283
|
+
* @return Return an object that contains the statistics collected internally by GLIDE core
|
|
5284
|
+
*/
|
|
5285
|
+
getStatistics(): object;
|
|
5219
5286
|
}
|
|
5220
5287
|
export {};
|
|
@@ -36,6 +36,43 @@ export declare namespace GlideClientConfiguration {
|
|
|
36
36
|
context?: any;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuration options for creating a {@link GlideClient | GlideClient}.
|
|
41
|
+
*
|
|
42
|
+
* Extends `BaseClientConfiguration` with properties specific to `GlideClient`, such as database selection,
|
|
43
|
+
* reconnection strategies, and Pub/Sub subscription settings.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* This configuration allows you to tailor the client's behavior when connecting to a standalone Valkey Glide server.
|
|
47
|
+
*
|
|
48
|
+
* - **Database Selection**: Use `databaseId` to specify which logical database to connect to.
|
|
49
|
+
* - **Reconnection Strategy**: Customize how the client should attempt reconnections using `connectionBackoff`.
|
|
50
|
+
* - `numberOfRetries`: The maximum number of retry attempts with increasing delays.
|
|
51
|
+
* - After this limit is reached, the retry interval becomes constant.
|
|
52
|
+
* - `factor`: A multiplier applied to the base delay between retries (e.g., `500` means a 500ms base delay).
|
|
53
|
+
* - `exponentBase`: The exponential growth factor for delays (e.g., `2` means the delay doubles with each retry).
|
|
54
|
+
* - **Pub/Sub Subscriptions**: Predefine Pub/Sub channels and patterns to subscribe to upon connection establishment.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const config: GlideClientConfiguration = {
|
|
59
|
+
* databaseId: 1,
|
|
60
|
+
* connectionBackoff: {
|
|
61
|
+
* numberOfRetries: 10, // Maximum retries before delay becomes constant
|
|
62
|
+
* factor: 500, // Base delay in milliseconds
|
|
63
|
+
* exponentBase: 2, // Delay doubles with each retry (2^N)
|
|
64
|
+
* },
|
|
65
|
+
* pubsubSubscriptions: {
|
|
66
|
+
* channelsAndPatterns: {
|
|
67
|
+
* [GlideClientConfiguration.PubSubChannelModes.Pattern]: new Set(['news.*']),
|
|
68
|
+
* },
|
|
69
|
+
* callback: (msg) => {
|
|
70
|
+
* console.log(`Received message on ${msg.channel}:`, msg.payload);
|
|
71
|
+
* },
|
|
72
|
+
* },
|
|
73
|
+
* };
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
39
76
|
export type GlideClientConfiguration = BaseClientConfiguration & {
|
|
40
77
|
/**
|
|
41
78
|
* index of the logical database to connect to.
|
|
@@ -82,7 +119,57 @@ export declare class GlideClient extends BaseClient {
|
|
|
82
119
|
* @internal
|
|
83
120
|
*/
|
|
84
121
|
protected createClientRequest(options: GlideClientConfiguration): connection_request.IConnectionRequest;
|
|
122
|
+
/**
|
|
123
|
+
* Creates a new `GlideClient` instance and establishes a connection to a standalone Valkey Glide server.
|
|
124
|
+
*
|
|
125
|
+
* @param options - The configuration options for the client, including server addresses, authentication credentials, TLS settings, database selection, reconnection strategy, and Pub/Sub subscriptions.
|
|
126
|
+
* @returns A promise that resolves to a connected `GlideClient` instance.
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* Use this static method to create and connect a `GlideClient` to a standalone Valkey Glide server. The client will automatically handle connection establishment, including any authentication and TLS configurations.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Connecting to a Standalone Server
|
|
134
|
+
* import { GlideClient, GlideClientConfiguration } from '@valkey/valkey-glide';
|
|
135
|
+
*
|
|
136
|
+
* const client = await GlideClient.createClient({
|
|
137
|
+
* addresses: [
|
|
138
|
+
* { host: 'primary.example.com', port: 6379 },
|
|
139
|
+
* { host: 'replica1.example.com', port: 6379 },
|
|
140
|
+
* ],
|
|
141
|
+
* databaseId: 1,
|
|
142
|
+
* credentials: {
|
|
143
|
+
* username: 'user1',
|
|
144
|
+
* password: 'passwordA',
|
|
145
|
+
* },
|
|
146
|
+
* useTLS: true,
|
|
147
|
+
* connectionBackoff: {
|
|
148
|
+
* numberOfRetries: 5,
|
|
149
|
+
* factor: 1000,
|
|
150
|
+
* exponentBase: 2,
|
|
151
|
+
* },
|
|
152
|
+
* pubsubSubscriptions: {
|
|
153
|
+
* channelsAndPatterns: {
|
|
154
|
+
* [GlideClientConfiguration.PubSubChannelModes.Exact]: new Set(['updates']),
|
|
155
|
+
* },
|
|
156
|
+
* callback: (msg) => {
|
|
157
|
+
* console.log(`Received message: ${msg.payload}`);
|
|
158
|
+
* },
|
|
159
|
+
* },
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
|
|
165
|
+
* - **TLS**: If `useTLS` is set to `true`, the client will establish a secure connection using TLS.
|
|
166
|
+
* - **Reconnection Strategy**: The `connectionBackoff` settings define how the client will attempt to reconnect in case of disconnections.
|
|
167
|
+
* - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
|
|
168
|
+
*/
|
|
85
169
|
static createClient(options: GlideClientConfiguration): Promise<GlideClient>;
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
86
173
|
static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClient>;
|
|
87
174
|
/**
|
|
88
175
|
* Execute a transaction by processing the queued commands.
|
|
@@ -59,6 +59,9 @@ export declare namespace GlideClusterClientConfiguration {
|
|
|
59
59
|
*/
|
|
60
60
|
Sharded = 2
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for Pub/Sub subscriptions that the client will establish upon connection.
|
|
64
|
+
*/
|
|
62
65
|
interface PubSubSubscriptions {
|
|
63
66
|
/**
|
|
64
67
|
* Channels and patterns by modes.
|
|
@@ -74,6 +77,39 @@ export declare namespace GlideClusterClientConfiguration {
|
|
|
74
77
|
context?: any;
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration options for creating a {@link GlideClusterClient | GlideClusterClient}.
|
|
82
|
+
*
|
|
83
|
+
* Extends `BaseClientConfiguration` with properties specific to `GlideClusterClient`, such as periodic topology checks
|
|
84
|
+
* and Pub/Sub subscription settings.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* This configuration allows you to tailor the client's behavior when connecting to a Valkey GLIDE Cluster.
|
|
88
|
+
*
|
|
89
|
+
* - **Periodic Topology Checks**: Use `periodicChecks` to configure how the client performs periodic checks to detect changes in the cluster's topology.
|
|
90
|
+
* - `"enabledDefaultConfigs"`: Enables periodic checks with default configurations.
|
|
91
|
+
* - `"disabled"`: Disables periodic topology checks.
|
|
92
|
+
* - `{ duration_in_sec: number }`: Manually configure the interval for periodic checks.
|
|
93
|
+
* - **Pub/Sub Subscriptions**: Predefine Pub/Sub channels and patterns to subscribe to upon connection establishment.
|
|
94
|
+
* - Supports exact channels, patterns, and sharded channels (available since Valkey version 7.0).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const config: GlideClusterClientConfiguration = {
|
|
99
|
+
* periodicChecks: {
|
|
100
|
+
* duration_in_sec: 30, // Perform periodic checks every 30 seconds
|
|
101
|
+
* },
|
|
102
|
+
* pubsubSubscriptions: {
|
|
103
|
+
* channelsAndPatterns: {
|
|
104
|
+
* [GlideClusterClientConfiguration.PubSubChannelModes.Pattern]: new Set(['cluster.*']),
|
|
105
|
+
* },
|
|
106
|
+
* callback: (msg) => {
|
|
107
|
+
* console.log(`Received message on ${msg.channel}:`, msg.payload);
|
|
108
|
+
* },
|
|
109
|
+
* },
|
|
110
|
+
* };
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
77
113
|
export type GlideClusterClientConfiguration = BaseClientConfiguration & {
|
|
78
114
|
/**
|
|
79
115
|
* Configure the periodic topology checks.
|
|
@@ -93,6 +129,37 @@ export type GlideClusterClientConfiguration = BaseClientConfiguration & {
|
|
|
93
129
|
* otherwise, we will get a dictionary of address: nodeResponse, address is of type string and nodeResponse is of type T.
|
|
94
130
|
*/
|
|
95
131
|
export type ClusterResponse<T> = T | Record<string, T>;
|
|
132
|
+
/**
|
|
133
|
+
* Routing configuration for commands based on a specific slot ID in a Valkey cluster.
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* This interface allows you to specify routing of a command to a node responsible for a particular slot ID in the cluster.
|
|
137
|
+
* Valkey clusters use hash slots to distribute data across multiple shards. There are 16,384 slots in total, and each shard
|
|
138
|
+
* manages a range of slots.
|
|
139
|
+
*
|
|
140
|
+
* - **Slot ID**: A number between 0 and 16383 representing a hash slot.
|
|
141
|
+
* - **Routing Type**:
|
|
142
|
+
* - `"primarySlotId"`: Routes the command to the primary node responsible for the specified slot ID.
|
|
143
|
+
* - `"replicaSlotId"`: Routes the command to a replica node responsible for the specified slot ID, overriding the `readFrom` configuration.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Route command to the primary node responsible for slot ID 12345
|
|
148
|
+
* const routeBySlotId: SlotIdTypes = {
|
|
149
|
+
* type: "primarySlotId",
|
|
150
|
+
* id: 12345,
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* // Route command to a replica node responsible for slot ID 12345
|
|
154
|
+
* const routeToReplicaBySlotId: SlotIdTypes = {
|
|
155
|
+
* type: "replicaSlotId",
|
|
156
|
+
* id: 12345,
|
|
157
|
+
* };
|
|
158
|
+
*
|
|
159
|
+
* // Use the routing configuration when executing a command
|
|
160
|
+
* const result = await client.get("mykey", { route: routeBySlotId });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
96
163
|
export interface SlotIdTypes {
|
|
97
164
|
/**
|
|
98
165
|
* `replicaSlotId` overrides the `readFrom` configuration. If it's used the request
|
|
@@ -105,6 +172,36 @@ export interface SlotIdTypes {
|
|
|
105
172
|
*/
|
|
106
173
|
id: number;
|
|
107
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Routing configuration for commands based on a key in a Valkey cluster.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* This interface allows you to specify routing of a command to a node responsible for the slot that a specific key hashes to.
|
|
180
|
+
* Valkey clusters use consistent hashing to map keys to hash slots, which are then managed by different shards in the cluster.
|
|
181
|
+
*
|
|
182
|
+
* - **Key**: The key whose hash slot will determine the routing of the command.
|
|
183
|
+
* - **Routing Type**:
|
|
184
|
+
* - `"primarySlotKey"`: Routes the command to the primary node responsible for the key's slot.
|
|
185
|
+
* - `"replicaSlotKey"`: Routes the command to a replica node responsible for the key's slot, overriding the `readFrom` configuration.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* // Route command to the primary node responsible for the key's slot
|
|
190
|
+
* const routeByKey: SlotKeyTypes = {
|
|
191
|
+
* type: "primarySlotKey",
|
|
192
|
+
* key: "user:1001",
|
|
193
|
+
* };
|
|
194
|
+
*
|
|
195
|
+
* // Route command to a replica node responsible for the key's slot
|
|
196
|
+
* const routeToReplicaByKey: SlotKeyTypes = {
|
|
197
|
+
* type: "replicaSlotKey",
|
|
198
|
+
* key: "user:1001",
|
|
199
|
+
* };
|
|
200
|
+
*
|
|
201
|
+
* // Use the routing configuration when executing a command
|
|
202
|
+
* const result = await client.get("user:1001", { route: routeByKey });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
108
205
|
export interface SlotKeyTypes {
|
|
109
206
|
/**
|
|
110
207
|
* `replicaSlotKey` overrides the `readFrom` configuration. If it's used the request
|
|
@@ -116,6 +213,39 @@ export interface SlotKeyTypes {
|
|
|
116
213
|
*/
|
|
117
214
|
key: string;
|
|
118
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Routing configuration to send a command to a specific node by its address and port.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* This interface allows you to specify routing of a command to a node in the Valkey cluster by providing its network address and port.
|
|
221
|
+
* It's useful when you need to direct a command to a particular node.
|
|
222
|
+
*
|
|
223
|
+
* - **Type**: Must be set to `"routeByAddress"` to indicate that the routing should be based on the provided address.
|
|
224
|
+
* - **Host**: The endpoint of the node.
|
|
225
|
+
* - If `port` is not provided, `host` should be in the format `${address}:${port}`, where `address` is the preferred endpoint as shown in the output of the `CLUSTER SLOTS` command.
|
|
226
|
+
* - If `port` is provided, `host` should be the address or hostname of the node without the port.
|
|
227
|
+
* - **Port**: (Optional) The port to access on the node.
|
|
228
|
+
* - If `port` is not provided, `host` is assumed to include the port number.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Route command to a node at '192.168.1.10:6379'
|
|
233
|
+
* const routeByAddress: RouteByAddress = {
|
|
234
|
+
* type: "routeByAddress",
|
|
235
|
+
* host: "192.168.1.10",
|
|
236
|
+
* port: 6379,
|
|
237
|
+
* };
|
|
238
|
+
*
|
|
239
|
+
* // Alternatively, include the port in the host string
|
|
240
|
+
* const routeByAddressWithPortInHost: RouteByAddress = {
|
|
241
|
+
* type: "routeByAddress",
|
|
242
|
+
* host: "192.168.1.10:6379",
|
|
243
|
+
* };
|
|
244
|
+
*
|
|
245
|
+
* // Use the routing configuration when executing a command
|
|
246
|
+
* const result = await client.ping({ route: routeByAddress });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
119
249
|
export interface RouteByAddress {
|
|
120
250
|
type: "routeByAddress";
|
|
121
251
|
/**
|
|
@@ -127,6 +257,52 @@ export interface RouteByAddress {
|
|
|
127
257
|
*/
|
|
128
258
|
port?: number;
|
|
129
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Defines the routing configuration for a command in a Valkey cluster.
|
|
262
|
+
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* The `Routes` type allows you to specify how a command should be routed in a Valkey cluster.
|
|
265
|
+
* Commands can be routed to a single node or broadcast to multiple nodes depending on the routing strategy.
|
|
266
|
+
*
|
|
267
|
+
* **Routing Options**:
|
|
268
|
+
*
|
|
269
|
+
* - **Single Node Routing** (`SingleNodeRoute`):
|
|
270
|
+
* - **"randomNode"**: Route the command to a random node in the cluster.
|
|
271
|
+
* - **`SlotIdTypes`**: Route based on a specific slot ID.
|
|
272
|
+
* - **`SlotKeyTypes`**: Route based on the slot of a specific key.
|
|
273
|
+
* - **`RouteByAddress`**: Route to a specific node by its address and port.
|
|
274
|
+
* - **Broadcast Routing**:
|
|
275
|
+
* - **"allPrimaries"**: Route the command to all primary nodes in the cluster.
|
|
276
|
+
* - **"allNodes"**: Route the command to all nodes (both primaries and replicas) in the cluster.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* // Route command to a random node
|
|
281
|
+
* const routeRandom: Routes = "randomNode";
|
|
282
|
+
*
|
|
283
|
+
* // Route command to all primary nodes
|
|
284
|
+
* const routeAllPrimaries: Routes = "allPrimaries";
|
|
285
|
+
*
|
|
286
|
+
* // Route command to all nodes
|
|
287
|
+
* const routeAllNodes: Routes = "allNodes";
|
|
288
|
+
*
|
|
289
|
+
* // Route command to a node by slot key
|
|
290
|
+
* const routeByKey: Routes = {
|
|
291
|
+
* type: "primarySlotKey",
|
|
292
|
+
* key: "myKey",
|
|
293
|
+
* };
|
|
294
|
+
*
|
|
295
|
+
* // Route command to a specific node by address
|
|
296
|
+
* const routeByAddress: Routes = {
|
|
297
|
+
* type: "routeByAddress",
|
|
298
|
+
* host: "192.168.1.10",
|
|
299
|
+
* port: 6379,
|
|
300
|
+
* };
|
|
301
|
+
*
|
|
302
|
+
* // Use the routing configuration when executing a command
|
|
303
|
+
* const result = await client.ping({ route: routeByAddress });
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
130
306
|
export type Routes = SingleNodeRoute
|
|
131
307
|
/**
|
|
132
308
|
* Route request to all primary nodes.
|
|
@@ -136,6 +312,48 @@ export type Routes = SingleNodeRoute
|
|
|
136
312
|
* Route request to all nodes.
|
|
137
313
|
*/
|
|
138
314
|
| "allNodes";
|
|
315
|
+
/**
|
|
316
|
+
* Defines the routing configuration to a single node in the Valkey cluster.
|
|
317
|
+
*
|
|
318
|
+
* @remarks
|
|
319
|
+
* The `SingleNodeRoute` type allows you to specify routing of a command to a single node in the cluster.
|
|
320
|
+
* This can be based on various criteria such as a random node, a node responsible for a specific slot, or a node identified by its address.
|
|
321
|
+
*
|
|
322
|
+
* **Options**:
|
|
323
|
+
*
|
|
324
|
+
* - **"randomNode"**: Route the command to a random node in the cluster.
|
|
325
|
+
* - **`SlotIdTypes`**: Route to the node responsible for a specific slot ID.
|
|
326
|
+
* - **`SlotKeyTypes`**: Route to the node responsible for the slot of a specific key.
|
|
327
|
+
* - **`RouteByAddress`**: Route to a specific node by its address and port.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* // Route to a random node
|
|
332
|
+
* const routeRandomNode: SingleNodeRoute = "randomNode";
|
|
333
|
+
*
|
|
334
|
+
* // Route based on slot ID
|
|
335
|
+
* const routeBySlotId: SingleNodeRoute = {
|
|
336
|
+
* type: "primarySlotId",
|
|
337
|
+
* id: 12345,
|
|
338
|
+
* };
|
|
339
|
+
*
|
|
340
|
+
* // Route based on key
|
|
341
|
+
* const routeByKey: SingleNodeRoute = {
|
|
342
|
+
* type: "primarySlotKey",
|
|
343
|
+
* key: "myKey",
|
|
344
|
+
* };
|
|
345
|
+
*
|
|
346
|
+
* // Route to a specific node by address
|
|
347
|
+
* const routeByAddress: SingleNodeRoute = {
|
|
348
|
+
* type: "routeByAddress",
|
|
349
|
+
* host: "192.168.1.10",
|
|
350
|
+
* port: 6379,
|
|
351
|
+
* };
|
|
352
|
+
*
|
|
353
|
+
* // Use the routing configuration when executing a command
|
|
354
|
+
* const result = await client.get("myKey", { route: routeByKey });
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
139
357
|
export type SingleNodeRoute =
|
|
140
358
|
/**
|
|
141
359
|
* Route request to a random node.
|
|
@@ -159,7 +377,55 @@ export declare class GlideClusterClient extends BaseClient {
|
|
|
159
377
|
* @internal
|
|
160
378
|
*/
|
|
161
379
|
protected createClientRequest(options: GlideClusterClientConfiguration): connection_request.IConnectionRequest;
|
|
380
|
+
/**
|
|
381
|
+
* Creates a new `GlideClusterClient` instance and establishes connections to a Valkey GLIDE Cluster.
|
|
382
|
+
*
|
|
383
|
+
* @param options - The configuration options for the client, including cluster addresses, authentication credentials, TLS settings, periodic checks, and Pub/Sub subscriptions.
|
|
384
|
+
* @returns A promise that resolves to a connected `GlideClusterClient` instance.
|
|
385
|
+
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* Use this static method to create and connect a `GlideClusterClient` to a Valkey GLIDE Cluster. The client will automatically handle connection establishment, including cluster topology discovery and handling of authentication and TLS configurations.
|
|
388
|
+
*
|
|
389
|
+
* ### Example - Connecting to a Cluster
|
|
390
|
+
* ```typescript
|
|
391
|
+
* import { GlideClusterClient, GlideClusterClientConfiguration } from '@valkey/valkey-glide';
|
|
392
|
+
*
|
|
393
|
+
* const client = await GlideClusterClient.createClient({
|
|
394
|
+
* addresses: [
|
|
395
|
+
* { host: 'address1.example.com', port: 6379 },
|
|
396
|
+
* { host: 'address2.example.com', port: 6379 },
|
|
397
|
+
* ],
|
|
398
|
+
* credentials: {
|
|
399
|
+
* username: 'user1',
|
|
400
|
+
* password: 'passwordA',
|
|
401
|
+
* },
|
|
402
|
+
* useTLS: true,
|
|
403
|
+
* periodicChecks: {
|
|
404
|
+
* duration_in_sec: 30, // Perform periodic checks every 30 seconds
|
|
405
|
+
* },
|
|
406
|
+
* pubsubSubscriptions: {
|
|
407
|
+
* channelsAndPatterns: {
|
|
408
|
+
* [GlideClusterClientConfiguration.PubSubChannelModes.Exact]: new Set(['updates']),
|
|
409
|
+
* [GlideClusterClientConfiguration.PubSubChannelModes.Sharded]: new Set(['sharded_channel']),
|
|
410
|
+
* },
|
|
411
|
+
* callback: (msg) => {
|
|
412
|
+
* console.log(`Received message: ${msg.payload}`);
|
|
413
|
+
* },
|
|
414
|
+
* },
|
|
415
|
+
* });
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* - **Cluster Topology Discovery**: The client will automatically discover the cluster topology based on the seed addresses provided.
|
|
420
|
+
* - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
|
|
421
|
+
* - **TLS**: If `useTLS` is set to `true`, the client will establish secure connections using TLS.
|
|
422
|
+
* - **Periodic Checks**: The `periodicChecks` setting allows you to configure how often the client checks for cluster topology changes.
|
|
423
|
+
* - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
|
|
424
|
+
*/
|
|
162
425
|
static createClient(options: GlideClusterClientConfiguration): Promise<GlideClusterClient>;
|
|
426
|
+
/**
|
|
427
|
+
* @internal
|
|
428
|
+
*/
|
|
163
429
|
static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClusterClient>;
|
|
164
430
|
/**
|
|
165
431
|
* @internal
|
|
@@ -444,7 +710,7 @@ export declare class GlideClusterClient extends BaseClient {
|
|
|
444
710
|
* @example
|
|
445
711
|
* ```typescript
|
|
446
712
|
* // Example usage of configSet method to set multiple configuration parameters
|
|
447
|
-
* const result = await client.configSet({ timeout: "1000", maxmemory
|
|
713
|
+
* const result = await client.configSet({ timeout: "1000", maxmemory: "1GB" });
|
|
448
714
|
* console.log(result); // Output: 'OK'
|
|
449
715
|
* ```
|
|
450
716
|
*/
|
|
@@ -995,7 +1261,7 @@ export declare class GlideClusterClient extends BaseClient {
|
|
|
995
1261
|
* @example
|
|
996
1262
|
* ```typescript
|
|
997
1263
|
* const luaScript = new Script("return { ARGV[1] }");
|
|
998
|
-
* const result = await invokeScript(luaScript, { args: ["bar"] });
|
|
1264
|
+
* const result = await client.invokeScript(luaScript, { args: ["bar"] });
|
|
999
1265
|
* console.log(result); // Output: ['bar']
|
|
1000
1266
|
* ```
|
|
1001
1267
|
*/
|