@valkey/valkey-glide 1.1.0-rc10
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/README.md +39 -0
- package/build-ts/index.d.ts +11 -0
- package/build-ts/index.js +184 -0
- package/build-ts/src/BaseClient.d.ts +5126 -0
- package/build-ts/src/Commands.d.ts +1800 -0
- package/build-ts/src/Errors.d.ts +21 -0
- package/build-ts/src/GlideClient.d.ts +737 -0
- package/build-ts/src/GlideClusterClient.d.ts +1057 -0
- package/build-ts/src/Logger.d.ts +31 -0
- package/build-ts/src/ProtobufMessage.d.ts +2 -0
- package/build-ts/src/Transaction.d.ts +2997 -0
- package/package.json +67 -0
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
3
|
+
*/
|
|
4
|
+
import * as net from "net";
|
|
5
|
+
import { BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
|
|
6
|
+
import { FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsFullResponse, InfoOptions, LolwutOptions, ScanOptions } from "./Commands";
|
|
7
|
+
import { connection_request } from "./ProtobufMessage";
|
|
8
|
+
import { Transaction } from "./Transaction";
|
|
9
|
+
export declare namespace GlideClientConfiguration {
|
|
10
|
+
/**
|
|
11
|
+
* Enum representing pubsub subscription modes.
|
|
12
|
+
* @see {@link https://valkey.io/docs/topics/pubsub/|Valkey PubSub Documentation} for more details.
|
|
13
|
+
*/
|
|
14
|
+
enum PubSubChannelModes {
|
|
15
|
+
/**
|
|
16
|
+
* Use exact channel names.
|
|
17
|
+
*/
|
|
18
|
+
Exact = 0,
|
|
19
|
+
/**
|
|
20
|
+
* Use channel name patterns.
|
|
21
|
+
*/
|
|
22
|
+
Pattern = 1
|
|
23
|
+
}
|
|
24
|
+
interface PubSubSubscriptions {
|
|
25
|
+
/**
|
|
26
|
+
* Channels and patterns by modes.
|
|
27
|
+
*/
|
|
28
|
+
channelsAndPatterns: Partial<Record<PubSubChannelModes, Set<string>>>;
|
|
29
|
+
/**
|
|
30
|
+
* Optional callback to accept the incoming messages.
|
|
31
|
+
*/
|
|
32
|
+
callback?: (msg: PubSubMsg, context: any) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Arbitrary context to pass to the callback.
|
|
35
|
+
*/
|
|
36
|
+
context?: any;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export type GlideClientConfiguration = BaseClientConfiguration & {
|
|
40
|
+
/**
|
|
41
|
+
* index of the logical database to connect to.
|
|
42
|
+
*/
|
|
43
|
+
databaseId?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Strategy used to determine how and when to reconnect, in case of connection failures.
|
|
46
|
+
* The time between attempts grows exponentially, to the formula rand(0 .. factor * (exponentBase ^ N)), where N is the number of failed attempts.
|
|
47
|
+
* The client will attempt to reconnect indefinitely. Once the maximum value is reached, that will remain the time between retry attempts until a
|
|
48
|
+
* reconnect attempt is succesful.
|
|
49
|
+
* If not set, a default backoff strategy will be used.
|
|
50
|
+
*/
|
|
51
|
+
connectionBackoff?: {
|
|
52
|
+
/**
|
|
53
|
+
* Number of retry attempts that the client should perform when disconnected from the server, where the time between retries increases.
|
|
54
|
+
* Once the retries have reached the maximum value, the time between retries will remain constant until a reconnect attempt is succesful.
|
|
55
|
+
* Value must be an integer.
|
|
56
|
+
*/
|
|
57
|
+
numberOfRetries: number;
|
|
58
|
+
/**
|
|
59
|
+
* The multiplier that will be applied to the waiting time between each retry.
|
|
60
|
+
* Value must be an integer.
|
|
61
|
+
*/
|
|
62
|
+
factor: number;
|
|
63
|
+
/**
|
|
64
|
+
* The exponent base configured for the strategy.
|
|
65
|
+
* Value must be an integer.
|
|
66
|
+
*/
|
|
67
|
+
exponentBase: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* PubSub subscriptions to be used for the client.
|
|
71
|
+
* Will be applied via SUBSCRIBE/PSUBSCRIBE commands during connection establishment.
|
|
72
|
+
*/
|
|
73
|
+
pubsubSubscriptions?: GlideClientConfiguration.PubSubSubscriptions;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Client used for connection to standalone servers.
|
|
77
|
+
*
|
|
78
|
+
* @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#standalone|Valkey Glide Wiki}.
|
|
79
|
+
*/
|
|
80
|
+
export declare class GlideClient extends BaseClient {
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
protected createClientRequest(options: GlideClientConfiguration): connection_request.IConnectionRequest;
|
|
85
|
+
static createClient(options: GlideClientConfiguration): Promise<GlideClient>;
|
|
86
|
+
static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClient>;
|
|
87
|
+
/**
|
|
88
|
+
* Execute a transaction by processing the queued commands.
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
|
|
91
|
+
*
|
|
92
|
+
* @param transaction - A {@link Transaction} object containing a list of commands to be executed.
|
|
93
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
94
|
+
* @returns A list of results corresponding to the execution of each command in the transaction.
|
|
95
|
+
* If a command returns a value, it will be included in the list. If a command doesn't return a value,
|
|
96
|
+
* the list entry will be `null`.
|
|
97
|
+
* If the transaction failed due to a `WATCH` command, `exec` will return `null`.
|
|
98
|
+
*/
|
|
99
|
+
exec(transaction: Transaction, options?: DecoderOption): Promise<GlideReturnType[] | null>;
|
|
100
|
+
/** Executes a single command, without checking inputs. Every part of the command, including subcommands,
|
|
101
|
+
* should be added as a separate value in args.
|
|
102
|
+
*
|
|
103
|
+
* Note: An error will occur if the string decoder is used with commands that return only bytes as a response.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command|Valkey Glide Wiki} for details on the restrictions and limitations of the custom command API.
|
|
106
|
+
*
|
|
107
|
+
* @param args - A list including the command name and arguments for the custom command.
|
|
108
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
109
|
+
* @returns The executed custom command return value.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Example usage of customCommand method to retrieve pub/sub clients
|
|
114
|
+
* const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"]);
|
|
115
|
+
* console.log(result); // Output: Returns a list of all pub/sub clients
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
customCommand(args: GlideString[], options?: DecoderOption): Promise<GlideReturnType>;
|
|
119
|
+
/**
|
|
120
|
+
* Pings the server.
|
|
121
|
+
*
|
|
122
|
+
* @see {@link https://valkey.io/commands/ping/|valkey.io} for details.
|
|
123
|
+
*
|
|
124
|
+
* @param options - (Optional) Additional parameters:
|
|
125
|
+
* - (Optional) `message` : a message to include in the `PING` command.
|
|
126
|
+
* + If not provided, the server will respond with `"PONG"`.
|
|
127
|
+
* + If provided, the server will respond with a copy of the message.
|
|
128
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
129
|
+
* @returns `"PONG"` if `message` is not provided, otherwise return a copy of `message`.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Example usage of ping method without any message
|
|
134
|
+
* const result = await client.ping();
|
|
135
|
+
* console.log(result); // Output: 'PONG'
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Example usage of ping method with a message
|
|
141
|
+
* const result = await client.ping("Hello");
|
|
142
|
+
* console.log(result); // Output: 'Hello'
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
ping(options?: {
|
|
146
|
+
message?: GlideString;
|
|
147
|
+
} & DecoderOption): Promise<GlideString>;
|
|
148
|
+
/**
|
|
149
|
+
* Gets information and statistics about the server.
|
|
150
|
+
*
|
|
151
|
+
* @see {@link https://valkey.io/commands/info/|valkey.io} for details.
|
|
152
|
+
*
|
|
153
|
+
* @param sections - (Optional) A list of {@link InfoOptions} values specifying which sections of information to retrieve.
|
|
154
|
+
* When no parameter is provided, {@link InfoOptions.Default|Default} is assumed.
|
|
155
|
+
* @returns A string containing the information for the sections requested.
|
|
156
|
+
*/
|
|
157
|
+
info(sections?: InfoOptions[]): Promise<string>;
|
|
158
|
+
/**
|
|
159
|
+
* Changes the currently selected database.
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://valkey.io/commands/select/|valkey.io} for details.
|
|
162
|
+
*
|
|
163
|
+
* @param index - The index of the database to select.
|
|
164
|
+
* @returns A simple `"OK"` response.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Example usage of select method
|
|
169
|
+
* const result = await client.select(2);
|
|
170
|
+
* console.log(result); // Output: 'OK'
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
select(index: number): Promise<"OK">;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the name of the primary's connection.
|
|
176
|
+
*
|
|
177
|
+
* @see {@link https://valkey.io/commands/client-getname/|valkey.io} for more details.
|
|
178
|
+
*
|
|
179
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
180
|
+
* @returns The name of the client connection as a string if a name is set, or `null` if no name is assigned.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // Example usage of client_getname method
|
|
185
|
+
* const result = await client.client_getname();
|
|
186
|
+
* console.log(result); // Output: 'Client Name'
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
clientGetName(options?: DecoderOption): Promise<GlideString | null>;
|
|
190
|
+
/**
|
|
191
|
+
* Rewrites the configuration file with the current configuration.
|
|
192
|
+
*
|
|
193
|
+
* @see {@link https://valkey.io/commands/config-rewrite/|valkey.io} for details.
|
|
194
|
+
*
|
|
195
|
+
* @returns "OK" when the configuration was rewritten properly. Otherwise, an error is thrown.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* // Example usage of configRewrite command
|
|
200
|
+
* const result = await client.configRewrite();
|
|
201
|
+
* console.log(result); // Output: 'OK'
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
configRewrite(): Promise<"OK">;
|
|
205
|
+
/**
|
|
206
|
+
* Resets the statistics reported by the server using the `INFO` and `LATENCY HISTOGRAM` commands.
|
|
207
|
+
*
|
|
208
|
+
* @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details.
|
|
209
|
+
*
|
|
210
|
+
* @returns always "OK".
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* // Example usage of configResetStat command
|
|
215
|
+
* const result = await client.configResetStat();
|
|
216
|
+
* console.log(result); // Output: 'OK'
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
configResetStat(): Promise<"OK">;
|
|
220
|
+
/**
|
|
221
|
+
* Returns the current connection ID.
|
|
222
|
+
*
|
|
223
|
+
* @see {@link https://valkey.io/commands/client-id/|valkey.io} for details.
|
|
224
|
+
*
|
|
225
|
+
* @returns The ID of the connection.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const result = await client.clientId();
|
|
230
|
+
* console.log("Connection id: " + result);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
clientId(): Promise<number>;
|
|
234
|
+
/**
|
|
235
|
+
* Reads the configuration parameters of the running server.
|
|
236
|
+
*
|
|
237
|
+
* @see {@link https://valkey.io/commands/config-get/|valkey.io} for details.
|
|
238
|
+
*
|
|
239
|
+
* @param parameters - A list of configuration parameter names to retrieve values for.
|
|
240
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
241
|
+
*
|
|
242
|
+
* @returns A map of values corresponding to the configuration parameters.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // Example usage of configGet method with multiple configuration parameters
|
|
247
|
+
* const result = await client.configGet(["timeout", "maxmemory"]);
|
|
248
|
+
* console.log(result); // Output: {'timeout': '1000', 'maxmemory': '1GB'}
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
configGet(parameters: string[], options?: DecoderOption): Promise<Record<string, GlideString>>;
|
|
252
|
+
/**
|
|
253
|
+
* Sets configuration parameters to the specified values.
|
|
254
|
+
*
|
|
255
|
+
* @see {@link https://valkey.io/commands/config-set/|valkey.io} for details.
|
|
256
|
+
* @param parameters - A map consisting of configuration parameters and their respective values to set.
|
|
257
|
+
* @returns `"OK"` when the configuration was set properly. Otherwise an error is thrown.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* // Example usage of configSet method to set multiple configuration parameters
|
|
262
|
+
* const result = await client.configSet({ timeout: "1000", maxmemory, "1GB" });
|
|
263
|
+
* console.log(result); // Output: 'OK'
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
configSet(parameters: Record<string, GlideString>): Promise<"OK">;
|
|
267
|
+
/**
|
|
268
|
+
* Echoes the provided `message` back.
|
|
269
|
+
*
|
|
270
|
+
* @see {@link https://valkey.io/commands/echo|valkey.io} for more details.
|
|
271
|
+
*
|
|
272
|
+
* @param message - The message to be echoed back.
|
|
273
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
274
|
+
* @returns The provided `message`.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* // Example usage of the echo command
|
|
279
|
+
* const echoedMessage = await client.echo("valkey-glide");
|
|
280
|
+
* console.log(echoedMessage); // Output: 'valkey-glide'
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
echo(message: GlideString, options?: DecoderOption): Promise<GlideString>;
|
|
284
|
+
/**
|
|
285
|
+
* Returns the server time.
|
|
286
|
+
*
|
|
287
|
+
* @see {@link https://valkey.io/commands/time/|valkey.io} for details.
|
|
288
|
+
*
|
|
289
|
+
* @returns The current server time as an `array` with two items:
|
|
290
|
+
* - A Unix timestamp,
|
|
291
|
+
* - The amount of microseconds already elapsed in the current second.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* console.log(await client.time()); // Output: ['1710925775', '913580']
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
time(): Promise<[string, string]>;
|
|
299
|
+
/**
|
|
300
|
+
* Copies the value stored at the `source` to the `destination` key. If `destinationDB` is specified,
|
|
301
|
+
* the value will be copied to the database specified, otherwise the current database will be used.
|
|
302
|
+
* When `replace` is true, removes the `destination` key first if it already exists, otherwise performs
|
|
303
|
+
* no action.
|
|
304
|
+
*
|
|
305
|
+
* @see {@link https://valkey.io/commands/copy/|valkey.io} for more details.
|
|
306
|
+
* @remarks Since Valkey version 6.2.0.
|
|
307
|
+
*
|
|
308
|
+
* @param source - The key to the source value.
|
|
309
|
+
* @param destination - The key where the value should be copied to.
|
|
310
|
+
* @param options - (Optional) Additional parameters:
|
|
311
|
+
* - (Optional) `destinationDB`: the alternative logical database index for the destination key.
|
|
312
|
+
* If not provided, the current database will be used.
|
|
313
|
+
* - (Optional) `replace`: if `true`, the `destination` key should be removed before copying the
|
|
314
|
+
* value to it. If not provided, no action will be performed if the key already exists.
|
|
315
|
+
* @returns `true` if `source` was copied, `false` if the `source` was not copied.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const result = await client.copy("set1", "set2");
|
|
320
|
+
* console.log(result); // Output: true - "set1" was copied to "set2".
|
|
321
|
+
* ```
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const result = await client.copy("set1", "set2", { replace: true });
|
|
324
|
+
* console.log(result); // Output: true - "set1" was copied to "set2".
|
|
325
|
+
* ```
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const result = await client.copy("set1", "set2", { destinationDB: 1, replace: false });
|
|
328
|
+
* console.log(result); // Output: true - "set1" was copied to "set2".
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
copy(source: GlideString, destination: GlideString, options?: {
|
|
332
|
+
destinationDB?: number;
|
|
333
|
+
replace?: boolean;
|
|
334
|
+
}): Promise<boolean>;
|
|
335
|
+
/**
|
|
336
|
+
* Move `key` from the currently selected database to the database specified by `dbIndex`.
|
|
337
|
+
*
|
|
338
|
+
* @see {@link https://valkey.io/commands/move/|valkey.io} for more details.
|
|
339
|
+
*
|
|
340
|
+
* @param key - The key to move.
|
|
341
|
+
* @param dbIndex - The index of the database to move `key` to.
|
|
342
|
+
* @returns `true` if `key` was moved, or `false` if the `key` already exists in the destination
|
|
343
|
+
* database or does not exist in the source database.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const result = await client.move("key", 1);
|
|
348
|
+
* console.log(result); // Output: true
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
move(key: GlideString, dbIndex: number): Promise<boolean>;
|
|
352
|
+
/**
|
|
353
|
+
* Displays a piece of generative computer art and the server version.
|
|
354
|
+
*
|
|
355
|
+
* @see {@link https://valkey.io/commands/lolwut/|valkey.io} for more details.
|
|
356
|
+
*
|
|
357
|
+
* @param options - (Optional) The LOLWUT options - see {@link LolwutOptions}.
|
|
358
|
+
* @returns A piece of generative computer art along with the current server version.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const response = await client.lolwut({ version: 6, parameters: [40, 20] });
|
|
363
|
+
* console.log(response); // Output: "Valkey ver. 7.2.3" - Indicates the current server version.
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
lolwut(options?: LolwutOptions): Promise<string>;
|
|
367
|
+
/**
|
|
368
|
+
* Deletes a library and all its functions.
|
|
369
|
+
*
|
|
370
|
+
* @see {@link https://valkey.io/commands/function-delete/|valkey.io} for details.
|
|
371
|
+
* @remarks Since Valkey version 7.0.0.
|
|
372
|
+
*
|
|
373
|
+
* @param libraryCode - The library name to delete.
|
|
374
|
+
* @returns A simple `"OK"` response.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const result = await client.functionDelete("libName");
|
|
379
|
+
* console.log(result); // Output: 'OK'
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
functionDelete(libraryCode: GlideString): Promise<"OK">;
|
|
383
|
+
/**
|
|
384
|
+
* Loads a library to Valkey.
|
|
385
|
+
*
|
|
386
|
+
* @see {@link https://valkey.io/commands/function-load/|valkey.io} for details.
|
|
387
|
+
* @remarks Since Valkey version 7.0.0.
|
|
388
|
+
*
|
|
389
|
+
* @param libraryCode - The source code that implements the library.
|
|
390
|
+
* @param options - (Optional) Additional parameters:
|
|
391
|
+
* - (Optional) `replace`: Whether the given library should overwrite a library with the same name if it
|
|
392
|
+
* already exists.
|
|
393
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
394
|
+
* @returns The library name that was loaded.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* const code = "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)";
|
|
399
|
+
* const result = await client.functionLoad(code, true);
|
|
400
|
+
* console.log(result); // Output: 'mylib'
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
functionLoad(libraryCode: GlideString, options?: {
|
|
404
|
+
replace?: boolean;
|
|
405
|
+
} & DecoderOption): Promise<GlideString>;
|
|
406
|
+
/**
|
|
407
|
+
* Deletes all function libraries.
|
|
408
|
+
*
|
|
409
|
+
* @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details.
|
|
410
|
+
* @remarks Since Valkey version 7.0.0.
|
|
411
|
+
*
|
|
412
|
+
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
413
|
+
* @returns A simple `"OK"` response.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* const result = await client.functionFlush(FlushMode.SYNC);
|
|
418
|
+
* console.log(result); // Output: 'OK'
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
functionFlush(mode?: FlushMode): Promise<"OK">;
|
|
422
|
+
/**
|
|
423
|
+
* Returns information about the functions and libraries.
|
|
424
|
+
*
|
|
425
|
+
* @see {@link https://valkey.io/commands/function-list/|valkey.io} for details.
|
|
426
|
+
* @remarks Since Valkey version 7.0.0.
|
|
427
|
+
*
|
|
428
|
+
* @param options - (Optional) See {@link FunctionListOptions} and {@link DecoderOption}.
|
|
429
|
+
* @returns Info about all or selected libraries and their functions in {@link FunctionListResponse} format.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* // Request info for specific library including the source code
|
|
434
|
+
* const result1 = await client.functionList({ libNamePattern: "myLib*", withCode: true });
|
|
435
|
+
* // Request info for all libraries
|
|
436
|
+
* const result2 = await client.functionList();
|
|
437
|
+
* console.log(result2); // Output:
|
|
438
|
+
* // [{
|
|
439
|
+
* // "library_name": "myLib5_backup",
|
|
440
|
+
* // "engine": "LUA",
|
|
441
|
+
* // "functions": [{
|
|
442
|
+
* // "name": "myfunc",
|
|
443
|
+
* // "description": null,
|
|
444
|
+
* // "flags": [ "no-writes" ],
|
|
445
|
+
* // }],
|
|
446
|
+
* // "library_code": "#!lua name=myLib5_backup \n redis.register_function('myfunc', function(keys, args) return args[1] end)"
|
|
447
|
+
* // }]
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
functionList(options?: FunctionListOptions & DecoderOption): Promise<FunctionListResponse>;
|
|
451
|
+
/**
|
|
452
|
+
* Returns information about the function that's currently running and information about the
|
|
453
|
+
* available execution engines.
|
|
454
|
+
*
|
|
455
|
+
* FUNCTION STATS runs on all nodes of the server, including primary and replicas.
|
|
456
|
+
* The response includes a mapping from node address to the command response for that node.
|
|
457
|
+
*
|
|
458
|
+
* @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details.
|
|
459
|
+
* @remarks Since Valkey version 7.0.0.
|
|
460
|
+
*
|
|
461
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
462
|
+
* @returns A Record where the key is the node address and the value is a Record with two keys:
|
|
463
|
+
* - `"running_script"`: Information about the running script, or `null` if no script is running.
|
|
464
|
+
* - `"engines"`: Information about available engines and their stats.
|
|
465
|
+
* - see example for more details.
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* const response = await client.functionStats();
|
|
469
|
+
* console.log(response); // Example output:
|
|
470
|
+
* // {
|
|
471
|
+
* // "127.0.0.1:6379": { // Response from the primary node
|
|
472
|
+
* // "running_script": {
|
|
473
|
+
* // "name": "foo",
|
|
474
|
+
* // "command": ["FCALL", "foo", "0", "hello"],
|
|
475
|
+
* // "duration_ms": 7758
|
|
476
|
+
* // },
|
|
477
|
+
* // "engines": {
|
|
478
|
+
* // "LUA": {
|
|
479
|
+
* // "libraries_count": 1,
|
|
480
|
+
* // "functions_count": 1
|
|
481
|
+
* // }
|
|
482
|
+
* // }
|
|
483
|
+
* // },
|
|
484
|
+
* // "127.0.0.1:6380": { // Response from a replica node
|
|
485
|
+
* // "running_script": null,
|
|
486
|
+
* // "engines": {
|
|
487
|
+
* // "LUA": {
|
|
488
|
+
* // "libraries_count": 1,
|
|
489
|
+
* // "functions_count": 1
|
|
490
|
+
* // }
|
|
491
|
+
* // }
|
|
492
|
+
* // }
|
|
493
|
+
* // }
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
functionStats(options?: DecoderOption): Promise<FunctionStatsFullResponse>;
|
|
497
|
+
/**
|
|
498
|
+
* Kills a function that is currently executing.
|
|
499
|
+
* `FUNCTION KILL` terminates read-only functions only.
|
|
500
|
+
* `FUNCTION KILL` runs on all nodes of the server, including primary and replicas.
|
|
501
|
+
*
|
|
502
|
+
* @see {@link https://valkey.io/commands/function-kill/|valkey.io} for details.
|
|
503
|
+
* @remarks Since Valkey version 7.0.0.
|
|
504
|
+
*
|
|
505
|
+
* @returns `"OK"` if function is terminated. Otherwise, throws an error.
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* await client.functionKill();
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
functionKill(): Promise<"OK">;
|
|
512
|
+
/**
|
|
513
|
+
* Returns the serialized payload of all loaded libraries.
|
|
514
|
+
*
|
|
515
|
+
* @see {@link https://valkey.io/commands/function-dump/|valkey.io} for details.
|
|
516
|
+
* @remarks Since Valkey version 7.0.0.
|
|
517
|
+
*
|
|
518
|
+
* @returns The serialized payload of all loaded libraries.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```typescript
|
|
522
|
+
* const data = await client.functionDump();
|
|
523
|
+
* // data can be used to restore loaded functions on any Valkey instance
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
functionDump(): Promise<Buffer>;
|
|
527
|
+
/**
|
|
528
|
+
* Restores libraries from the serialized payload returned by {@link functionDump}.
|
|
529
|
+
*
|
|
530
|
+
* @see {@link https://valkey.io/commands/function-restore/|valkey.io} for details.
|
|
531
|
+
* @remarks Since Valkey version 7.0.0.
|
|
532
|
+
*
|
|
533
|
+
* @param payload - The serialized data from {@link functionDump}.
|
|
534
|
+
* @param policy - (Optional) A policy for handling existing libraries, see {@link FunctionRestorePolicy}.
|
|
535
|
+
* {@link FunctionRestorePolicy.APPEND} is used by default.
|
|
536
|
+
* @returns `"OK"`.
|
|
537
|
+
*
|
|
538
|
+
* @example
|
|
539
|
+
* ```typescript
|
|
540
|
+
* await client.functionRestore(data, FunctionRestorePolicy.FLUSH);
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
functionRestore(payload: Buffer, policy?: FunctionRestorePolicy): Promise<"OK">;
|
|
544
|
+
/**
|
|
545
|
+
* Deletes all the keys of all the existing databases. This command never fails.
|
|
546
|
+
*
|
|
547
|
+
* @see {@link https://valkey.io/commands/flushall/|valkey.io} for more details.
|
|
548
|
+
*
|
|
549
|
+
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
550
|
+
* @returns `"OK"`.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```typescript
|
|
554
|
+
* const result = await client.flushall(FlushMode.SYNC);
|
|
555
|
+
* console.log(result); // Output: 'OK'
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
flushall(mode?: FlushMode): Promise<"OK">;
|
|
559
|
+
/**
|
|
560
|
+
* Deletes all the keys of the currently selected database. This command never fails.
|
|
561
|
+
*
|
|
562
|
+
* @see {@link https://valkey.io/commands/flushdb/|valkey.io} for more details.
|
|
563
|
+
*
|
|
564
|
+
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
565
|
+
* @returns `"OK"`.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const result = await client.flushdb(FlushMode.SYNC);
|
|
570
|
+
* console.log(result); // Output: 'OK'
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
flushdb(mode?: FlushMode): Promise<"OK">;
|
|
574
|
+
/**
|
|
575
|
+
* Returns the number of keys in the currently selected database.
|
|
576
|
+
*
|
|
577
|
+
* @see {@link https://valkey.io/commands/dbsize/|valkey.io} for more details.
|
|
578
|
+
*
|
|
579
|
+
* @returns The number of keys in the currently selected database.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* const numKeys = await client.dbsize();
|
|
584
|
+
* console.log("Number of keys in the current database: ", numKeys);
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
dbsize(): Promise<number>;
|
|
588
|
+
/** Publish a message on pubsub channel.
|
|
589
|
+
*
|
|
590
|
+
* @see {@link https://valkey.io/commands/publish/|valkey.io} for more details.
|
|
591
|
+
*
|
|
592
|
+
* @param message - Message to publish.
|
|
593
|
+
* @param channel - Channel to publish the message on.
|
|
594
|
+
* @returns - Number of subscriptions in primary node that received the message.
|
|
595
|
+
* Note that this value does not include subscriptions that configured on replicas.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* // Example usage of publish command
|
|
600
|
+
* const result = await client.publish("Hi all!", "global-channel");
|
|
601
|
+
* console.log(result); // Output: 1 - This message was posted to 1 subscription which is configured on primary node
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
publish(message: GlideString, channel: GlideString): Promise<number>;
|
|
605
|
+
/**
|
|
606
|
+
* Returns `UNIX TIME` of the last DB save timestamp or startup timestamp if no save
|
|
607
|
+
* was made since then.
|
|
608
|
+
*
|
|
609
|
+
* @see {@link https://valkey.io/commands/lastsave/|valkey.io} for more details.
|
|
610
|
+
*
|
|
611
|
+
* @returns `UNIX TIME` of the last DB save executed with success.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* const timestamp = await client.lastsave();
|
|
616
|
+
* console.log("Last DB save was done at " + timestamp);
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
lastsave(): Promise<number>;
|
|
620
|
+
/**
|
|
621
|
+
* Returns a random existing key name from the currently selected database.
|
|
622
|
+
*
|
|
623
|
+
* @see {@link https://valkey.io/commands/randomkey/|valkey.io} for more details.
|
|
624
|
+
* @param options - (Optional) See {@link DecoderOption}.
|
|
625
|
+
* @returns A random existing key name from the currently selected database.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```typescript
|
|
629
|
+
* const result = await client.randomKey();
|
|
630
|
+
* console.log(result); // Output: "key12" - "key12" is a random existing key name from the currently selected database.
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
633
|
+
randomKey(options?: DecoderOption): Promise<GlideString | null>;
|
|
634
|
+
/**
|
|
635
|
+
* Flushes all the previously watched keys for a transaction. Executing a transaction will
|
|
636
|
+
* automatically flush all previously watched keys.
|
|
637
|
+
*
|
|
638
|
+
* @see {@link https://valkey.io/commands/unwatch/|valkey.io} and {@link https://valkey.io/topics/transactions/#cas|Valkey Glide Wiki} for more details.
|
|
639
|
+
*
|
|
640
|
+
* @returns A simple `"OK"` response.
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* let response = await client.watch(["sampleKey"]);
|
|
645
|
+
* console.log(response); // Output: "OK"
|
|
646
|
+
* response = await client.unwatch();
|
|
647
|
+
* console.log(response); // Output: "OK"
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
unwatch(): Promise<"OK">;
|
|
651
|
+
/**
|
|
652
|
+
* Checks existence of scripts in the script cache by their SHA1 digest.
|
|
653
|
+
*
|
|
654
|
+
* @see {@link https://valkey.io/commands/script-exists/|valkey.io} for more details.
|
|
655
|
+
*
|
|
656
|
+
* @param sha1s - List of SHA1 digests of the scripts to check.
|
|
657
|
+
* @returns A list of boolean values indicating the existence of each script.
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```typescript
|
|
661
|
+
* console result = await client.scriptExists(["sha1_digest1", "sha1_digest2"]);
|
|
662
|
+
* console.log(result); // Output: [true, false]
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
scriptExists(sha1s: GlideString[]): Promise<boolean[]>;
|
|
666
|
+
/**
|
|
667
|
+
* Flushes the Lua scripts cache.
|
|
668
|
+
*
|
|
669
|
+
* @see {@link https://valkey.io/commands/script-flush/|valkey.io} for more details.
|
|
670
|
+
*
|
|
671
|
+
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
672
|
+
* @returns A simple `"OK"` response.
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```typescript
|
|
676
|
+
* console result = await client.scriptFlush(FlushMode.SYNC);
|
|
677
|
+
* console.log(result); // Output: "OK"
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
scriptFlush(mode?: FlushMode): Promise<"OK">;
|
|
681
|
+
/**
|
|
682
|
+
* Kills the currently executing Lua script, assuming no write operation was yet performed by the script.
|
|
683
|
+
*
|
|
684
|
+
* @see {@link https://valkey.io/commands/script-kill/|valkey.io} for more details.
|
|
685
|
+
*
|
|
686
|
+
* @returns A simple `"OK"` response.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* console result = await client.scriptKill();
|
|
691
|
+
* console.log(result); // Output: "OK"
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
scriptKill(): Promise<"OK">;
|
|
695
|
+
/**
|
|
696
|
+
* Incrementally iterate over a collection of keys.
|
|
697
|
+
* `SCAN` is a cursor based iterator. This means that at every call of the method,
|
|
698
|
+
* the server returns an updated cursor that the user needs to use as the cursor argument in the next call.
|
|
699
|
+
* An iteration starts when the cursor is set to "0", and terminates when the cursor returned by the server is "0".
|
|
700
|
+
*
|
|
701
|
+
* A full iteration always retrieves all the elements that were present
|
|
702
|
+
* in the collection from the start to the end of a full iteration.
|
|
703
|
+
* Elements that were not constantly present in the collection during a full iteration, may be returned or not.
|
|
704
|
+
*
|
|
705
|
+
* @see {@link https://valkey.io/commands/scan|valkey.io} for more details.
|
|
706
|
+
*
|
|
707
|
+
* @param cursor - The `cursor` used for iteration. For the first iteration, the cursor should be set to "0".
|
|
708
|
+
* Using a non-zero cursor in the first iteration,
|
|
709
|
+
* or an invalid cursor at any iteration, will lead to undefined results.
|
|
710
|
+
* Using the same cursor in multiple iterations will, in case nothing changed between the iterations,
|
|
711
|
+
* return the same elements multiple times.
|
|
712
|
+
* If the the db has changed, it may result in undefined behavior.
|
|
713
|
+
* @param options - (Optional) The options to use for the scan operation, see {@link ScanOptions} and {@link DecoderOption}.
|
|
714
|
+
* @returns A List containing the next cursor value and a list of keys,
|
|
715
|
+
* formatted as [cursor, [key1, key2, ...]]
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```typescript
|
|
719
|
+
* // Example usage of scan method
|
|
720
|
+
* let result = await client.scan('0');
|
|
721
|
+
* console.log(result); // Output: ['17', ['key1', 'key2', 'key3', 'key4', 'key5', 'set1', 'set2', 'set3']]
|
|
722
|
+
* let firstCursorResult = result[0];
|
|
723
|
+
* result = await client.scan(firstCursorResult);
|
|
724
|
+
* console.log(result); // Output: ['349', ['key4', 'key5', 'set1', 'hash1', 'zset1', 'list1', 'list2',
|
|
725
|
+
* // 'list3', 'zset2', 'zset3', 'zset4', 'zset5', 'zset6']]
|
|
726
|
+
* result = await client.scan(result[0]);
|
|
727
|
+
* console.log(result); // Output: ['0', ['key6', 'key7']]
|
|
728
|
+
*
|
|
729
|
+
* result = await client.scan(firstCursorResult, {match: 'key*', count: 2});
|
|
730
|
+
* console.log(result); // Output: ['6', ['key4', 'key5']]
|
|
731
|
+
*
|
|
732
|
+
* result = await client.scan("0", {type: ObjectType.Set});
|
|
733
|
+
* console.log(result); // Output: ['362', ['set1', 'set2', 'set3']]
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
scan(cursor: GlideString, options?: ScanOptions & DecoderOption): Promise<[GlideString, GlideString[]]>;
|
|
737
|
+
}
|