@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.
@@ -0,0 +1,1057 @@
1
+ /**
2
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
+ */
4
+ import { ClusterScanCursor } from "glide-rs";
5
+ import { Script } from "index";
6
+ import * as net from "net";
7
+ import { BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
8
+ import { FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsSingleResponse, InfoOptions, LolwutOptions, ScanOptions } from "./Commands";
9
+ import { command_request, connection_request } from "./ProtobufMessage";
10
+ import { ClusterTransaction } from "./Transaction";
11
+ /** An extension to command option types with {@link Routes}. */
12
+ export interface RouteOption {
13
+ /**
14
+ * Specifies the routing configuration for the command.
15
+ * The client will route the command to the nodes defined by `route`.
16
+ */
17
+ route?: Routes;
18
+ }
19
+ /**
20
+ * Represents a manually configured interval for periodic checks.
21
+ */
22
+ export interface PeriodicChecksManualInterval {
23
+ /**
24
+ * The duration in seconds for the interval between periodic checks.
25
+ */
26
+ duration_in_sec: number;
27
+ }
28
+ /**
29
+ * Periodic checks configuration.
30
+ */
31
+ export type PeriodicChecks =
32
+ /**
33
+ * Enables the periodic checks with the default configurations.
34
+ */
35
+ "enabledDefaultConfigs"
36
+ /**
37
+ * Disables the periodic checks.
38
+ */
39
+ | "disabled"
40
+ /**
41
+ * Manually configured interval for periodic checks.
42
+ */
43
+ | PeriodicChecksManualInterval;
44
+ export declare namespace GlideClusterClientConfiguration {
45
+ /**
46
+ * Enum representing pubsub subscription modes.
47
+ * @see {@link https://valkey.io/docs/topics/pubsub/|Valkey PubSub Documentation} for more details.
48
+ */
49
+ enum PubSubChannelModes {
50
+ /**
51
+ * Use exact channel names.
52
+ */
53
+ Exact = 0,
54
+ /**
55
+ * Use channel name patterns.
56
+ */
57
+ Pattern = 1,
58
+ /**
59
+ * Use sharded pubsub. Available since Valkey version 7.0.
60
+ */
61
+ Sharded = 2
62
+ }
63
+ interface PubSubSubscriptions {
64
+ /**
65
+ * Channels and patterns by modes.
66
+ */
67
+ channelsAndPatterns: Partial<Record<PubSubChannelModes, Set<string>>>;
68
+ /**
69
+ * Optional callback to accept the incoming messages.
70
+ */
71
+ callback?: (msg: PubSubMsg, context: any) => void;
72
+ /**
73
+ * Arbitrary context to pass to the callback.
74
+ */
75
+ context?: any;
76
+ }
77
+ }
78
+ export type GlideClusterClientConfiguration = BaseClientConfiguration & {
79
+ /**
80
+ * Configure the periodic topology checks.
81
+ * These checks evaluate changes in the cluster's topology, triggering a slot refresh when detected.
82
+ * Periodic checks ensure a quick and efficient process by querying a limited number of nodes.
83
+ * If not set, `enabledDefaultConfigs` will be used.
84
+ */
85
+ periodicChecks?: PeriodicChecks;
86
+ /**
87
+ * PubSub subscriptions to be used for the client.
88
+ * Will be applied via SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE commands during connection establishment.
89
+ */
90
+ pubsubSubscriptions?: GlideClusterClientConfiguration.PubSubSubscriptions;
91
+ };
92
+ /**
93
+ * If the command's routing is to one node we will get T as a response type,
94
+ * otherwise, we will get a dictionary of address: nodeResponse, address is of type string and nodeResponse is of type T.
95
+ */
96
+ export type ClusterResponse<T> = T | Record<string, T>;
97
+ export interface SlotIdTypes {
98
+ /**
99
+ * `replicaSlotId` overrides the `readFrom` configuration. If it's used the request
100
+ * will be routed to a replica, even if the strategy is `alwaysFromPrimary`.
101
+ */
102
+ type: "primarySlotId" | "replicaSlotId";
103
+ /**
104
+ * Slot number. There are 16384 slots in a Valkey cluster, and each shard manages a slot range.
105
+ * Unless the slot is known, it's better to route using `SlotKeyTypes`
106
+ */
107
+ id: number;
108
+ }
109
+ export interface SlotKeyTypes {
110
+ /**
111
+ * `replicaSlotKey` overrides the `readFrom` configuration. If it's used the request
112
+ * will be routed to a replica, even if the strategy is `alwaysFromPrimary`.
113
+ */
114
+ type: "primarySlotKey" | "replicaSlotKey";
115
+ /**
116
+ * The request will be sent to nodes managing this key.
117
+ */
118
+ key: string;
119
+ }
120
+ export interface RouteByAddress {
121
+ type: "routeByAddress";
122
+ /**
123
+ *The endpoint of the node. If `port` is not provided, should be in the `${address}:${port}` format, where `address` is the preferred endpoint as shown in the output of the `CLUSTER SLOTS` command.
124
+ */
125
+ host: string;
126
+ /**
127
+ * The port to access on the node. If port is not provided, `host` is assumed to be in the format `${address}:${port}`.
128
+ */
129
+ port?: number;
130
+ }
131
+ export type Routes = SingleNodeRoute
132
+ /**
133
+ * Route request to all primary nodes.
134
+ */
135
+ | "allPrimaries"
136
+ /**
137
+ * Route request to all nodes.
138
+ */
139
+ | "allNodes";
140
+ export type SingleNodeRoute =
141
+ /**
142
+ * Route request to a random node.
143
+ */
144
+ "randomNode"
145
+ /**
146
+ * Route request to the node that contains the slot with the given id.
147
+ */
148
+ | SlotIdTypes
149
+ /**
150
+ * Route request to the node that contains the slot that the given key matches.
151
+ */
152
+ | SlotKeyTypes | RouteByAddress;
153
+ /**
154
+ * Client used for connection to cluster servers.
155
+ *
156
+ * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster|Valkey Glide Wiki}.
157
+ */
158
+ export declare class GlideClusterClient extends BaseClient {
159
+ /**
160
+ * @internal
161
+ */
162
+ protected createClientRequest(options: GlideClusterClientConfiguration): connection_request.IConnectionRequest;
163
+ static createClient(options: GlideClusterClientConfiguration): Promise<GlideClusterClient>;
164
+ static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClusterClient>;
165
+ /**
166
+ * @internal
167
+ */
168
+ protected scanOptionsToProto(cursor: string, options?: ScanOptions): command_request.ClusterScan;
169
+ /**
170
+ * @internal
171
+ */
172
+ protected createClusterScanPromise(cursor: ClusterScanCursor, options?: ScanOptions & DecoderOption): Promise<[ClusterScanCursor, GlideString[]]>;
173
+ /**
174
+ * Incrementally iterates over the keys in the Cluster.
175
+ *
176
+ * This command is similar to the `SCAN` command but designed for Cluster environments.
177
+ * It uses a {@link ClusterScanCursor} object to manage iterations.
178
+ *
179
+ * For each iteration, use the new cursor object to continue the scan.
180
+ * Using the same cursor object for multiple iterations may result in unexpected behavior.
181
+ *
182
+ * For more information about the Cluster Scan implementation, see
183
+ * {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#cluster-scan | Cluster Scan}.
184
+ *
185
+ * This method can iterate over all keys in the database from the start of the scan until it ends.
186
+ * The same key may be returned in multiple scan iterations.
187
+ * The API does not accept `route` as it go through all slots in the cluster.
188
+ *
189
+ * @see {@link https://valkey.io/commands/scan/ | valkey.io} for more details.
190
+ *
191
+ * @param cursor - The cursor object that wraps the scan state.
192
+ * To start a new scan, create a new empty `ClusterScanCursor` using {@link ClusterScanCursor}.
193
+ * @param options - (Optional) The scan options, see {@link ScanOptions} and {@link DecoderOption}.
194
+ * @returns A Promise resolving to an array containing the next cursor and an array of keys,
195
+ * formatted as [`ClusterScanCursor`, `string[]`].
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // Iterate over all keys in the cluster
200
+ * await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "key3", value: "value3"}]);
201
+ * let cursor = new ClusterScanCursor();
202
+ * const allKeys: GlideString[] = [];
203
+ * let keys: GlideString[] = [];
204
+ * while (!cursor.isFinished()) {
205
+ * [cursor, keys] = await client.scan(cursor, { count: 10 });
206
+ * allKeys.push(...keys);
207
+ * }
208
+ * console.log(allKeys); // ["key1", "key2", "key3"]
209
+ *
210
+ * // Iterate over keys matching a pattern
211
+ * await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "notMykey", value: "value3"}, {key: "somethingElse", value: "value4"}]);
212
+ * let cursor = new ClusterScanCursor();
213
+ * const matchedKeys: GlideString[] = [];
214
+ * while (!cursor.isFinished()) {
215
+ * const [cursor, keys] = await client.scan(cursor, { match: "*key*", count: 10 });
216
+ * matchedKeys.push(...keys);
217
+ * }
218
+ * console.log(matchedKeys); // ["key1", "key2", "notMykey"]
219
+ *
220
+ * // Iterate over keys of a specific type
221
+ * await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "key3", value: "value3"}]);
222
+ * await client.sadd("thisIsASet", ["value4"]);
223
+ * let cursor = new ClusterScanCursor();
224
+ * const stringKeys: GlideString[] = [];
225
+ * while (!cursor.isFinished()) {
226
+ * const [cursor, keys] = await client.scan(cursor, { type: object.STRING });
227
+ * stringKeys.push(...keys);
228
+ * }
229
+ * console.log(stringKeys); // ["key1", "key2", "key3"]
230
+ * ```
231
+ */
232
+ scan(cursor: ClusterScanCursor, options?: ScanOptions & DecoderOption): Promise<[ClusterScanCursor, GlideString[]]>;
233
+ /** Executes a single command, without checking inputs. Every part of the command, including subcommands,
234
+ * should be added as a separate value in args.
235
+ * The command will be routed automatically based on the passed command's default request policy, unless `route` is provided,
236
+ * in which case the client will route the command to the nodes defined by `route`.
237
+ *
238
+ * Note: An error will occur if the string decoder is used with commands that return only bytes as a response.
239
+ *
240
+ * @see {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command|Glide for Valkey Wiki} for details on the restrictions and limitations of the custom command API.
241
+ *
242
+ * @param args - A list including the command name and arguments for the custom command.
243
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}
244
+ * @returns The executed custom command return value.
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * // Example usage of customCommand method to retrieve pub/sub clients with routing to all primary nodes
249
+ * const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"], {route: "allPrimaries", decoder: Decoder.String});
250
+ * console.log(result); // Output: Returns a list of all pub/sub clients
251
+ * ```
252
+ */
253
+ customCommand(args: GlideString[], options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideReturnType>>;
254
+ /**
255
+ * Execute a transaction by processing the queued commands.
256
+ *
257
+ * @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
258
+ *
259
+ * @param transaction - A {@link ClusterTransaction} object containing a list of commands to be executed.
260
+ *
261
+ * @param options - (Optional) Additional parameters:
262
+ * - (Optional) `route`: If `route` is not provided, the transaction will be routed to the slot owner of the first key found in the transaction.
263
+ * If no key is found, the command will be sent to a random node.
264
+ * If `route` is provided, the client will route the command to the nodes defined by `route`.
265
+ * - (Optional) `decoder`: See {@link DecoderOption}.
266
+ * @returns A list of results corresponding to the execution of each command in the transaction.
267
+ * If a command returns a value, it will be included in the list. If a command doesn't return a value,
268
+ * the list entry will be `null`.
269
+ * If the transaction failed due to a `WATCH` command, `exec` will return `null`.
270
+ */
271
+ exec(transaction: ClusterTransaction, options?: {
272
+ route?: SingleNodeRoute;
273
+ } & DecoderOption): Promise<GlideReturnType[] | null>;
274
+ /**
275
+ * Pings the server.
276
+ *
277
+ * The command will be routed to all primary nodes, unless `route` is provided.
278
+ *
279
+ * @see {@link https://valkey.io/commands/ping/|valkey.io} for details.
280
+ *
281
+ * @param options - (Optional) Additional parameters:
282
+ * - (Optional) `message` : a message to include in the `PING` command.
283
+ * + If not provided, the server will respond with `"PONG"`.
284
+ * + If provided, the server will respond with a copy of the message.
285
+ * - (Optional) `route`: see {@link RouteOption}.
286
+ * - (Optional) `decoder`: see {@link DecoderOption}.
287
+ * @returns `"PONG"` if `message` is not provided, otherwise return a copy of `message`.
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * // Example usage of ping method without any message
292
+ * const result = await client.ping();
293
+ * console.log(result); // Output: 'PONG'
294
+ * ```
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * // Example usage of ping method with a message
299
+ * const result = await client.ping("Hello");
300
+ * console.log(result); // Output: 'Hello'
301
+ * ```
302
+ */
303
+ ping(options?: {
304
+ message?: GlideString;
305
+ } & RouteOption & DecoderOption): Promise<GlideString>;
306
+ /**
307
+ * Gets information and statistics about the server.
308
+ *
309
+ * The command will be routed to all primary nodes, unless `route` is provided.
310
+ *
311
+ * @see {@link https://valkey.io/commands/info/|valkey.io} for details.
312
+ *
313
+ * @param options - (Optional) Additional parameters:
314
+ * - (Optional) `sections`: a list of {@link InfoOptions} values specifying which sections of information to retrieve.
315
+ * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed.
316
+ * - (Optional) `route`: see {@link RouteOption}.
317
+ * @returns A string containing the information for the sections requested.
318
+ * When specifying a route other than a single node,
319
+ * it returns a dictionary where each address is the key and its corresponding node response is the value.
320
+ */
321
+ info(options?: {
322
+ sections?: InfoOptions[];
323
+ } & RouteOption): Promise<ClusterResponse<string>>;
324
+ /**
325
+ * Gets the name of the connection to which the request is routed.
326
+ *
327
+ * The command will be routed to a random node, unless `route` is provided.
328
+ *
329
+ * @see {@link https://valkey.io/commands/client-getname/|valkey.io} for details.
330
+ *
331
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
332
+ *
333
+ * @returns - The name of the client connection as a string if a name is set, or `null` if no name is assigned.
334
+ * When specifying a route other than a single node, it returns a dictionary where each address is the key and
335
+ * its corresponding node response is the value.
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * // Example usage of client_getname method
340
+ * const result = await client.client_getname();
341
+ * console.log(result); // Output: 'Connection Name'
342
+ * ```
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * // Example usage of clientGetName method with routing to all nodes
347
+ * const result = await client.clientGetName('allNodes');
348
+ * console.log(result); // Output: {'addr': 'Connection Name', 'addr2': 'Connection Name', 'addr3': 'Connection Name'}
349
+ * ```
350
+ */
351
+ clientGetName(options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideString | null>>;
352
+ /**
353
+ * Rewrites the configuration file with the current configuration.
354
+ *
355
+ * The command will be routed to a all nodes, unless `route` is provided.
356
+ *
357
+ * @see {@link https://valkey.io/commands/config-rewrite/|valkey.io} for details.
358
+ *
359
+ * @param options - (Optional) See {@link RouteOption}.
360
+ * @returns `"OK"` when the configuration was rewritten properly. Otherwise, an error is thrown.
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * // Example usage of configRewrite command
365
+ * const result = await client.configRewrite();
366
+ * console.log(result); // Output: 'OK'
367
+ * ```
368
+ */
369
+ configRewrite(options?: RouteOption): Promise<"OK">;
370
+ /**
371
+ * Resets the statistics reported by the server using the `INFO` and `LATENCY HISTOGRAM` commands.
372
+ *
373
+ * The command will be routed to all nodes, unless `route` is provided.
374
+ *
375
+ * @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details.
376
+ *
377
+ * @param options - (Optional) See {@link RouteOption}.
378
+ * @returns always `"OK"`.
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * // Example usage of configResetStat command
383
+ * const result = await client.configResetStat();
384
+ * console.log(result); // Output: 'OK'
385
+ * ```
386
+ */
387
+ configResetStat(options?: RouteOption): Promise<"OK">;
388
+ /**
389
+ * Returns the current connection ID.
390
+ *
391
+ * The command will be routed to a random node, unless `route` is provided.
392
+ *
393
+ * @see {@link https://valkey.io/commands/client-id/|valkey.io} for details.
394
+ *
395
+ * @param options - (Optional) See {@link RouteOption}.
396
+ * @returns The ID of the connection. When specifying a route other than a single node,
397
+ * it returns a dictionary where each address is the key and its corresponding node response is the value.
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * const result = await client.clientId();
402
+ * console.log("Connection id: " + result);
403
+ * ```
404
+ */
405
+ clientId(options?: RouteOption): Promise<ClusterResponse<number>>;
406
+ /**
407
+ * Reads the configuration parameters of the running server.
408
+ *
409
+ * The command will be routed to a random node, unless `route` is provided.
410
+ *
411
+ * @see {@link https://valkey.io/commands/config-get/|valkey.io} for details.
412
+ *
413
+ * @param parameters - A list of configuration parameter names to retrieve values for.
414
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
415
+ *
416
+ * @returns A map of values corresponding to the configuration parameters. When specifying a route other than a single node,
417
+ * it returns a dictionary where each address is the key and its corresponding node response is the value.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * // Example usage of config_get method with a single configuration parameter with routing to a random node
422
+ * const result = await client.config_get(["timeout"], "randomNode");
423
+ * console.log(result); // Output: {'timeout': '1000'}
424
+ * ```
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * // Example usage of configGet method with multiple configuration parameters
429
+ * const result = await client.configGet(["timeout", "maxmemory"]);
430
+ * console.log(result); // Output: {'timeout': '1000', 'maxmemory': '1GB'}
431
+ * ```
432
+ */
433
+ configGet(parameters: string[], options?: RouteOption & DecoderOption): Promise<ClusterResponse<Record<string, GlideString>>>;
434
+ /**
435
+ * Sets configuration parameters to the specified values.
436
+ *
437
+ * The command will be routed to all nodes, unless `route` is provided.
438
+ *
439
+ * @see {@link https://valkey.io/commands/config-set/|valkey.io} for details.
440
+ *
441
+ * @param parameters - A map consisting of configuration parameters and their respective values to set.
442
+ * @param options - (Optional) See {@link RouteOption}.
443
+ * @returns "OK" when the configuration was set properly. Otherwise an error is thrown.
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * // Example usage of configSet method to set multiple configuration parameters
448
+ * const result = await client.configSet({ timeout: "1000", maxmemory, "1GB" });
449
+ * console.log(result); // Output: 'OK'
450
+ * ```
451
+ */
452
+ configSet(parameters: Record<string, GlideString>, options?: RouteOption): Promise<"OK">;
453
+ /**
454
+ * Echoes the provided `message` back.
455
+ *
456
+ * The command will be routed to a random node, unless `route` is provided.
457
+ *
458
+ * @see {@link https://valkey.io/commands/echo/|valkey.io} for details.
459
+ *
460
+ * @param message - The message to be echoed back.
461
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
462
+ * @returns The provided `message`. When specifying a route other than a single node,
463
+ * it returns a dictionary where each address is the key and its corresponding node response is the value.
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * // Example usage of the echo command
468
+ * const echoedMessage = await client.echo("valkey-glide");
469
+ * console.log(echoedMessage); // Output: "valkey-glide"
470
+ * ```
471
+ * @example
472
+ * ```typescript
473
+ * // Example usage of the echo command with routing to all nodes
474
+ * const echoedMessage = await client.echo("valkey-glide", "allNodes");
475
+ * console.log(echoedMessage); // Output: {'addr': 'valkey-glide', 'addr2': 'valkey-glide', 'addr3': 'valkey-glide'}
476
+ * ```
477
+ */
478
+ echo(message: GlideString, options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideString>>;
479
+ /**
480
+ * Returns the server time.
481
+ *
482
+ * The command will be routed to a random node, unless `route` is provided.
483
+ *
484
+ * @see {@link https://valkey.io/commands/time/|valkey.io} for details.
485
+ *
486
+ * @param options - (Optional) See {@link RouteOption}.
487
+ *
488
+ * @returns The current server time as an `array` with two items:
489
+ * - A Unix timestamp,
490
+ * - The amount of microseconds already elapsed in the current second.
491
+ *
492
+ * When specifying a route other than a single node, it returns a dictionary where each address is the key and
493
+ * its corresponding node response is the value.
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * // Example usage of time method without any argument
498
+ * const result = await client.time();
499
+ * console.log(result); // Output: ['1710925775', '913580']
500
+ * ```
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * // Example usage of time method with routing to all nodes
505
+ * const result = await client.time('allNodes');
506
+ * console.log(result); // Output: {'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']}
507
+ * ```
508
+ */
509
+ time(options?: RouteOption): Promise<ClusterResponse<[string, string]>>;
510
+ /**
511
+ * Copies the value stored at the `source` to the `destination` key. When `replace` is `true`,
512
+ * removes the `destination` key first if it already exists, otherwise performs no action.
513
+ *
514
+ * @see {@link https://valkey.io/commands/copy/|valkey.io} for details.
515
+ * @remarks When in cluster mode, `source` and `destination` must map to the same hash slot.
516
+ * @remarks Since Valkey version 6.2.0.
517
+ *
518
+ * @param source - The key to the source value.
519
+ * @param destination - The key where the value should be copied to.
520
+ * @param options - (Optional) Additional parameters:
521
+ * - (Optional) `replace`: if `true`, the `destination` key should be removed before copying the
522
+ * value to it. If not provided, no action will be performed if the key already exists.
523
+ * @returns `true` if `source` was copied, `false` if the `source` was not copied.
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * const result = await client.copy("set1", "set2", { replace: true });
528
+ * console.log(result); // Output: true - "set1" was copied to "set2".
529
+ * ```
530
+ */
531
+ copy(source: GlideString, destination: GlideString, options?: {
532
+ replace?: boolean;
533
+ }): Promise<boolean>;
534
+ /**
535
+ * Displays a piece of generative computer art and the server version.
536
+ *
537
+ * The command will be routed to a random node, unless `route` is provided.
538
+ *
539
+ * @see {@link https://valkey.io/commands/lolwut/|valkey.io} for details.
540
+ *
541
+ * @param options - (Optional) The LOLWUT options - see {@link LolwutOptions} and {@link RouteOption}.
542
+ * @returns A piece of generative computer art along with the current server version.
543
+ *
544
+ * @example
545
+ * ```typescript
546
+ * const response = await client.lolwut({ version: 6, parameters: [40, 20] }, "allNodes");
547
+ * console.log(response); // Output: "Valkey ver. 7.2.3" - Indicates the current server version.
548
+ * ```
549
+ */
550
+ lolwut(options?: LolwutOptions & RouteOption): Promise<ClusterResponse<string>>;
551
+ /**
552
+ * Invokes a previously loaded function.
553
+ *
554
+ * The command will be routed to a random node, unless `route` is provided.
555
+ *
556
+ * @see {@link https://valkey.io/commands/fcall/|valkey.io} for details.
557
+ * @remarks Since Valkey version 7.0.0.
558
+ *
559
+ * @param func - The function name.
560
+ * @param args - A list of `function` arguments and it should not represent names of keys.
561
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
562
+ * @returns The invoked function's return value.
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * const response = await client.fcallWithRoute("Deep_Thought", [], "randomNode");
567
+ * console.log(response); // Output: Returns the function's return value.
568
+ * ```
569
+ */
570
+ fcallWithRoute(func: GlideString, args: GlideString[], options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideReturnType>>;
571
+ /**
572
+ * Invokes a previously loaded read-only function.
573
+ *
574
+ * The command will be routed to a random node, unless `route` is provided.
575
+ *
576
+ * @see {@link https://valkey.io/commands/fcall/|valkey.io} for details.
577
+ * @remarks Since Valkey version 7.0.0.
578
+ *
579
+ * @param func - The function name.
580
+ * @param args - A list of `function` arguments and it should not represent names of keys.
581
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
582
+ * @returns The invoked function's return value.
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * const response = await client.fcallReadonlyWithRoute("Deep_Thought", ["Answer", "to", "the", "Ultimate",
587
+ * "Question", "of", "Life,", "the", "Universe,", "and", "Everything"], "randomNode");
588
+ * console.log(response); // Output: 42 # The return value on the function that was execute.
589
+ * ```
590
+ */
591
+ fcallReadonlyWithRoute(func: GlideString, args: GlideString[], options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideReturnType>>;
592
+ /**
593
+ * Deletes a library and all its functions.
594
+ *
595
+ * @see {@link https://valkey.io/commands/function-delete/|valkey.io} for details.
596
+ * @remarks Since Valkey version 7.0.0.
597
+ *
598
+ * @param libraryCode - The library name to delete.
599
+ * @param route - (Optional) The command will be routed to all primary node, unless `route` is provided, in which
600
+ * case the client will route the command to the nodes defined by `route`.
601
+ * @returns A simple `"OK"` response.
602
+ *
603
+ * @example
604
+ * ```typescript
605
+ * const result = await client.functionDelete("libName");
606
+ * console.log(result); // Output: 'OK'
607
+ * ```
608
+ */
609
+ functionDelete(libraryCode: GlideString, options?: RouteOption): Promise<"OK">;
610
+ /**
611
+ * Loads a library to Valkey.
612
+ *
613
+ * @see {@link https://valkey.io/commands/function-load/|valkey.io} for details.
614
+ * @remarks Since Valkey version 7.0.0.
615
+ *
616
+ * @param libraryCode - The source code that implements the library.
617
+ * @param options - (Optional) Additional parameters:
618
+ * - (Optional) `replace`: whether the given library should overwrite a library with the same name if it
619
+ * already exists.
620
+ * - (Optional) `route`: see {@link RouteOption}.
621
+ * - (Optional) `decoder`: see {@link DecoderOption}.
622
+ * @returns The library name that was loaded.
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * const code = "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)";
627
+ * const result = await client.functionLoad(code, true, 'allNodes');
628
+ * console.log(result); // Output: 'mylib'
629
+ * ```
630
+ */
631
+ functionLoad(libraryCode: GlideString, options?: {
632
+ replace?: boolean;
633
+ } & RouteOption & DecoderOption): Promise<GlideString>;
634
+ /**
635
+ * Deletes all function libraries.
636
+ *
637
+ * @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details.
638
+ * @remarks Since Valkey version 7.0.0.
639
+ *
640
+ * @param options - (Optional) Additional parameters:
641
+ * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
642
+ * - (Optional) `route`: see {@link RouteOption}.
643
+ * @returns A simple `"OK"` response.
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * const result = await client.functionFlush(FlushMode.SYNC);
648
+ * console.log(result); // Output: 'OK'
649
+ * ```
650
+ */
651
+ functionFlush(options?: {
652
+ mode?: FlushMode;
653
+ } & RouteOption): Promise<"OK">;
654
+ /**
655
+ * Returns information about the functions and libraries.
656
+ *
657
+ * The command will be routed to a random node, unless `route` is provided.
658
+ *
659
+ * @see {@link https://valkey.io/commands/function-list/|valkey.io} for details.
660
+ * @remarks Since Valkey version 7.0.0.
661
+ *
662
+ * @param options - (Optional) See {@link FunctionListOptions}, {@link DecoderOption}, and {@link RouteOption}.
663
+ * @returns Info about all or selected libraries and their functions in {@link FunctionListResponse} format.
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * // Request info for specific library including the source code
668
+ * const result1 = await client.functionList({ libNamePattern: "myLib*", withCode: true });
669
+ * // Request info for all libraries
670
+ * const result2 = await client.functionList();
671
+ * console.log(result2); // Output:
672
+ * // [{
673
+ * // "library_name": "myLib5_backup",
674
+ * // "engine": "LUA",
675
+ * // "functions": [{
676
+ * // "name": "myfunc",
677
+ * // "description": null,
678
+ * // "flags": [ "no-writes" ],
679
+ * // }],
680
+ * // "library_code": "#!lua name=myLib5_backup \n redis.register_function('myfunc', function(keys, args) return args[1] end)"
681
+ * // }]
682
+ * ```
683
+ */
684
+ functionList(options?: FunctionListOptions & DecoderOption & RouteOption): Promise<ClusterResponse<FunctionListResponse>>;
685
+ /**
686
+ * Returns information about the function that's currently running and information about the
687
+ * available execution engines.
688
+ *
689
+ * The command will be routed to all primary nodes, unless `route` is provided.
690
+ *
691
+ * @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details.
692
+ * @remarks Since Valkey version 7.0.0.
693
+ *
694
+ * @param options - (Optional) See {@link DecoderOption} and {@link RouteOption}.
695
+ * @returns A `Record` with two keys:
696
+ * - `"running_script"` with information about the running script.
697
+ * - `"engines"` with information about available engines and their stats.
698
+ * - See example for more details.
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * const response = await client.functionStats("randomNode");
703
+ * console.log(response); // Output:
704
+ * // {
705
+ * // "running_script":
706
+ * // {
707
+ * // "name": "deep_thought",
708
+ * // "command": ["fcall", "deep_thought", "0"],
709
+ * // "duration_ms": 5008
710
+ * // },
711
+ * // "engines":
712
+ * // {
713
+ * // "LUA":
714
+ * // {
715
+ * // "libraries_count": 2,
716
+ * // "functions_count": 3
717
+ * // }
718
+ * // }
719
+ * // }
720
+ * // Output if no scripts running:
721
+ * // {
722
+ * // "running_script": null
723
+ * // "engines":
724
+ * // {
725
+ * // "LUA":
726
+ * // {
727
+ * // "libraries_count": 2,
728
+ * // "functions_count": 3
729
+ * // }
730
+ * // }
731
+ * // }
732
+ * ```
733
+ */
734
+ functionStats(options?: RouteOption & DecoderOption): Promise<ClusterResponse<FunctionStatsSingleResponse>>;
735
+ /**
736
+ * Kills a function that is currently executing.
737
+ * `FUNCTION KILL` terminates read-only functions only.
738
+ *
739
+ * @see {@link https://valkey.io/commands/function-kill/|valkey.io} for details.
740
+ * @remarks Since Valkey version 7.0.0.
741
+ *
742
+ * @param options - (Optional) See {@link RouteOption}.
743
+ * @returns `"OK"` if function is terminated. Otherwise, throws an error.
744
+ *
745
+ * @example
746
+ * ```typescript
747
+ * await client.functionKill();
748
+ * ```
749
+ */
750
+ functionKill(options?: RouteOption): Promise<"OK">;
751
+ /**
752
+ * Returns the serialized payload of all loaded libraries.
753
+ *
754
+ * @see {@link https://valkey.io/commands/function-dump/|valkey.io} for details.
755
+ * @remarks Since Valkey version 7.0.0.
756
+ *
757
+ * @param options - (Optional) See {@link RouteOption}.
758
+ * @returns The serialized payload of all loaded libraries.
759
+ *
760
+ * @example
761
+ * ```typescript
762
+ * const data = await client.functionDump();
763
+ * // data can be used to restore loaded functions on any Valkey instance
764
+ * ```
765
+ */
766
+ functionDump(options?: RouteOption): Promise<ClusterResponse<Buffer>>;
767
+ /**
768
+ * Restores libraries from the serialized payload returned by {@link functionDump}.
769
+ *
770
+ * @see {@link https://valkey.io/commands/function-restore/|valkey.io} for details.
771
+ * @remarks Since Valkey version 7.0.0.
772
+ *
773
+ * @param payload - The serialized data from {@link functionDump}.
774
+ * @param options - (Optional) Additional parameters:
775
+ * - (Optional) `policy`: a policy for handling existing libraries, see {@link FunctionRestorePolicy}.
776
+ * {@link FunctionRestorePolicy.APPEND} is used by default.
777
+ * - (Optional) `route`: see {@link RouteOption}.
778
+ * @returns `"OK"`.
779
+ *
780
+ * @example
781
+ * ```typescript
782
+ * await client.functionRestore(data, { policy: FunctionRestorePolicy.FLUSH, route: "allPrimaries" });
783
+ * ```
784
+ */
785
+ functionRestore(payload: Buffer, options?: {
786
+ policy?: FunctionRestorePolicy;
787
+ } & RouteOption): Promise<"OK">;
788
+ /**
789
+ * Deletes all the keys of all the existing databases. This command never fails.
790
+ *
791
+ * The command will be routed to all primary nodes, unless `route` is provided.
792
+ *
793
+ * @see {@link https://valkey.io/commands/flushall/|valkey.io} for details.
794
+ *
795
+ * @param options - (Optional) Additional parameters:
796
+ * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
797
+ * - (Optional) `route`: see {@link RouteOption}.
798
+ * @returns `OK`.
799
+ *
800
+ * @example
801
+ * ```typescript
802
+ * const result = await client.flushall(FlushMode.SYNC);
803
+ * console.log(result); // Output: 'OK'
804
+ * ```
805
+ */
806
+ flushall(options?: {
807
+ mode?: FlushMode;
808
+ } & RouteOption): Promise<"OK">;
809
+ /**
810
+ * Deletes all the keys of the currently selected database. This command never fails.
811
+ *
812
+ * The command will be routed to all primary nodes, unless `route` is provided.
813
+ *
814
+ * @see {@link https://valkey.io/commands/flushdb/|valkey.io} for details.
815
+ *
816
+ * @param options - (Optional) Additional parameters:
817
+ * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
818
+ * - (Optional) `route`: see {@link RouteOption}.
819
+ * @returns `OK`.
820
+ *
821
+ * @example
822
+ * ```typescript
823
+ * const result = await client.flushdb(FlushMode.SYNC);
824
+ * console.log(result); // Output: 'OK'
825
+ * ```
826
+ */
827
+ flushdb(options?: {
828
+ mode?: FlushMode;
829
+ } & RouteOption): Promise<"OK">;
830
+ /**
831
+ * Returns the number of keys in the database.
832
+ *
833
+ * The command will be routed to all nodes, unless `route` is provided.
834
+ *
835
+ * @see {@link https://valkey.io/commands/dbsize/|valkey.io} for details.
836
+ *
837
+ * @param options - (Optional) See {@link RouteOption}.
838
+ * @returns The number of keys in the database.
839
+ * In the case of routing the query to multiple nodes, returns the aggregated number of keys across the different nodes.
840
+ *
841
+ * @example
842
+ * ```typescript
843
+ * const numKeys = await client.dbsize("allPrimaries");
844
+ * console.log("Number of keys across all primary nodes: ", numKeys);
845
+ * ```
846
+ */
847
+ dbsize(options?: RouteOption): Promise<number>;
848
+ /** Publish a message on pubsub channel.
849
+ * This command aggregates PUBLISH and SPUBLISH commands functionalities.
850
+ * The mode is selected using the 'sharded' parameter.
851
+ * For both sharded and non-sharded mode, request is routed using hashed channel as key.
852
+ *
853
+ * @see {@link https://valkey.io/commands/publish} and {@link https://valkey.io/commands/spublish} for more details.
854
+ *
855
+ * @param message - Message to publish.
856
+ * @param channel - Channel to publish the message on.
857
+ * @param sharded - Use sharded pubsub mode. Available since Valkey version 7.0.
858
+ * @returns - Number of subscriptions in primary node that received the message.
859
+ *
860
+ * @example
861
+ * ```typescript
862
+ * // Example usage of publish command
863
+ * const result = await client.publish("Hi all!", "global-channel");
864
+ * console.log(result); // Output: 1 - This message was posted to 1 subscription which is configured on primary node
865
+ * ```
866
+ *
867
+ * @example
868
+ * ```typescript
869
+ * // Example usage of spublish command
870
+ * const result = await client.publish("Hi all!", "global-channel", true);
871
+ * console.log(result); // Output: 2 - Published 2 instances of "Hi to sharded channel1!" message on channel1 using sharded mode
872
+ * ```
873
+ */
874
+ publish(message: GlideString, channel: GlideString, sharded?: boolean): Promise<number>;
875
+ /**
876
+ * Lists the currently active shard channels.
877
+ * The command is routed to all nodes, and aggregates the response to a single array.
878
+ *
879
+ * @see {@link https://valkey.io/commands/pubsub-shardchannels/|valkey.io} for details.
880
+ *
881
+ * @param options - (Optional) Additional parameters:
882
+ * - (Optional) `pattern`: A glob-style pattern to match active shard channels.
883
+ * If not provided, all active shard channels are returned.
884
+ * - (Optional) `decoder`: see {@link DecoderOption}.
885
+ * @returns A list of currently active shard channels matching the given pattern.
886
+ * If no pattern is specified, all active shard channels are returned.
887
+ *
888
+ * @example
889
+ * ```typescript
890
+ * const allChannels = await client.pubsubShardchannels();
891
+ * console.log(allChannels); // Output: ["channel1", "channel2"]
892
+ *
893
+ * const filteredChannels = await client.pubsubShardchannels("channel*");
894
+ * console.log(filteredChannels); // Output: ["channel1", "channel2"]
895
+ * ```
896
+ */
897
+ pubsubShardChannels(options?: {
898
+ pattern?: GlideString;
899
+ } & DecoderOption): Promise<GlideString[]>;
900
+ /**
901
+ * Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified shard channels.
902
+ *
903
+ * @see {@link https://valkey.io/commands/pubsub-shardnumsub/|valkey.io} for details.
904
+ * @remarks The command is routed to all nodes, and aggregates the response into a single list.
905
+ *
906
+ * @param channels - The list of shard channels to query for the number of subscribers.
907
+ * @param options - (Optional) see {@link DecoderOption}.
908
+ * @returns A list of the shard channel names and their numbers of subscribers.
909
+ *
910
+ * @example
911
+ * ```typescript
912
+ * const result1 = await client.pubsubShardnumsub(["channel1", "channel2"]);
913
+ * console.log(result1); // Output:
914
+ * // [{ channel: "channel1", numSub: 3}, { channel: "channel2", numSub: 5 }]
915
+ *
916
+ * const result2 = await client.pubsubShardnumsub([]);
917
+ * console.log(result2); // Output: []
918
+ * ```
919
+ */
920
+ pubsubShardNumSub(channels: GlideString[], options?: DecoderOption): Promise<{
921
+ channel: GlideString;
922
+ numSub: number;
923
+ }[]>;
924
+ /**
925
+ * Returns `UNIX TIME` of the last DB save timestamp or startup timestamp if no save
926
+ * was made since then.
927
+ *
928
+ * The command will be routed to a random node, unless `route` is provided.
929
+ *
930
+ * @see {@link https://valkey.io/commands/lastsave/|valkey.io} for details.
931
+ *
932
+ * @param options - (Optional) See {@link RouteOption}.
933
+ * @returns `UNIX TIME` of the last DB save executed with success.
934
+ *
935
+ * @example
936
+ * ```typescript
937
+ * const timestamp = await client.lastsave();
938
+ * console.log("Last DB save was done at " + timestamp);
939
+ * ```
940
+ */
941
+ lastsave(options?: RouteOption): Promise<ClusterResponse<number>>;
942
+ /**
943
+ * Returns a random existing key name.
944
+ *
945
+ * The command will be routed to all primary nodes, unless `route` is provided.
946
+ *
947
+ * @see {@link https://valkey.io/commands/randomkey/|valkey.io} for details.
948
+ *
949
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
950
+ * @returns A random existing key name.
951
+ *
952
+ * @example
953
+ * ```typescript
954
+ * const result = await client.randomKey();
955
+ * console.log(result); // Output: "key12" - "key12" is a random existing key name.
956
+ * ```
957
+ */
958
+ randomKey(options?: DecoderOption & RouteOption): Promise<GlideString | null>;
959
+ /**
960
+ * Flushes all the previously watched keys for a transaction. Executing a transaction will
961
+ * automatically flush all previously watched keys.
962
+ *
963
+ * The command will be routed to all primary nodes, unless `route` is provided
964
+ *
965
+ * @see {@link https://valkey.io/commands/unwatch/|valkey.io} and {@link https://valkey.io/topics/transactions/#cas|Valkey Glide Wiki} for more details.
966
+ *
967
+ * @param options - (Optional) See {@link RouteOption}.
968
+ * @returns A simple `"OK"` response.
969
+ *
970
+ * @example
971
+ * ```typescript
972
+ * let response = await client.watch(["sampleKey"]);
973
+ * console.log(response); // Output: "OK"
974
+ * response = await client.unwatch();
975
+ * console.log(response); // Output: "OK"
976
+ * ```
977
+ */
978
+ unwatch(options?: RouteOption): Promise<"OK">;
979
+ /**
980
+ * Invokes a Lua script with arguments.
981
+ * This method simplifies the process of invoking scripts on a Valkey server by using an object that represents a Lua script.
982
+ * The script loading, argument preparation, and execution will all be handled internally. If the script has not already been loaded,
983
+ * it will be loaded automatically using the `SCRIPT LOAD` command. After that, it will be invoked using the `EVALSHA` command.
984
+ *
985
+ * The command will be routed to a random node, unless `route` is provided.
986
+ *
987
+ * @see {@link https://valkey.io/commands/script-load/|SCRIPT LOAD} and {@link https://valkey.io/commands/evalsha/|EVALSHA} on valkey.io for details.
988
+ *
989
+ * @param script - The Lua script to execute.
990
+ * @param options - (Optional) Additional parameters:
991
+ * - (Optional) `args`: the arguments for the script.
992
+ * - (Optional) `decoder`: see {@link DecoderOption}.
993
+ * - (Optional) `route`: see {@link RouteOption}.
994
+ * @returns A value that depends on the script that was executed.
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const luaScript = new Script("return { ARGV[1] }");
999
+ * const result = await invokeScript(luaScript, { args: ["bar"] });
1000
+ * console.log(result); // Output: ['bar']
1001
+ * ```
1002
+ */
1003
+ invokeScriptWithRoute(script: Script, options?: {
1004
+ args?: GlideString[];
1005
+ } & DecoderOption & RouteOption): Promise<ClusterResponse<GlideReturnType>>;
1006
+ /**
1007
+ * Checks existence of scripts in the script cache by their SHA1 digest.
1008
+ *
1009
+ * @see {@link https://valkey.io/commands/script-exists/|valkey.io} for more details.
1010
+ *
1011
+ * @param sha1s - List of SHA1 digests of the scripts to check.
1012
+ * @param options - (Optional) See {@link RouteOption}.
1013
+ * @returns A list of boolean values indicating the existence of each script.
1014
+ *
1015
+ * @example
1016
+ * ```typescript
1017
+ * console result = await client.scriptExists(["sha1_digest1", "sha1_digest2"]);
1018
+ * console.log(result); // Output: [true, false]
1019
+ * ```
1020
+ */
1021
+ scriptExists(sha1s: GlideString[], options?: RouteOption): Promise<ClusterResponse<boolean[]>>;
1022
+ /**
1023
+ * Flushes the Lua scripts cache.
1024
+ *
1025
+ * @see {@link https://valkey.io/commands/script-flush/|valkey.io} for more details.
1026
+ *
1027
+ * @param options - (Optional) Additional parameters:
1028
+ * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
1029
+ * - (Optional) `route`: see {@link RouteOption}.
1030
+ * @returns A simple `"OK"` response.
1031
+ *
1032
+ * @example
1033
+ * ```typescript
1034
+ * console result = await client.scriptFlush(FlushMode.SYNC);
1035
+ * console.log(result); // Output: "OK"
1036
+ * ```
1037
+ */
1038
+ scriptFlush(options?: {
1039
+ mode?: FlushMode;
1040
+ } & RouteOption): Promise<"OK">;
1041
+ /**
1042
+ * Kills the currently executing Lua script, assuming no write operation was yet performed by the script.
1043
+ *
1044
+ * @see {@link https://valkey.io/commands/script-kill/|valkey.io} for more details.
1045
+ * @remarks The command is routed to all nodes, and aggregates the response to a single array.
1046
+ *
1047
+ * @param options - (Optional) See {@link RouteOption}.
1048
+ * @returns A simple `"OK"` response.
1049
+ *
1050
+ * @example
1051
+ * ```typescript
1052
+ * console result = await client.scriptKill();
1053
+ * console.log(result); // Output: "OK"
1054
+ * ```
1055
+ */
1056
+ scriptKill(options?: RouteOption): Promise<"OK">;
1057
+ }