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