@valkey/valkey-glide 1.3.4 → 1.3.5-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/LICENSE +201 -0
- package/README.md +53 -18
- package/build-ts/{src/BaseClient.d.ts → BaseClient.d.ts} +62 -118
- package/build-ts/BaseClient.js +6049 -0
- package/build-ts/{src/Transaction.d.ts → Batch.d.ts} +124 -67
- package/build-ts/Batch.js +3457 -0
- package/build-ts/{src/Commands.d.ts → Commands.d.ts} +171 -791
- package/build-ts/Commands.js +2708 -0
- package/build-ts/Errors.js +42 -0
- package/build-ts/{src/GlideClient.d.ts → GlideClient.d.ts} +55 -19
- package/build-ts/GlideClient.js +899 -0
- package/build-ts/{src/GlideClusterClient.d.ts → GlideClusterClient.d.ts} +78 -42
- package/build-ts/GlideClusterClient.js +1251 -0
- package/build-ts/Logger.d.ts +47 -0
- package/build-ts/Logger.js +78 -0
- package/build-ts/{src/ProtobufMessage.d.ts → ProtobufMessage.d.ts} +135 -634
- package/build-ts/ProtobufMessage.js +5159 -0
- package/build-ts/index.d.ts +16 -11
- package/build-ts/index.js +53 -216
- package/build-ts/native.d.ts +92 -0
- package/build-ts/native.js +365 -0
- package/build-ts/server-modules/GlideFt.js +628 -0
- package/build-ts/{src/server-modules → server-modules}/GlideFtOptions.d.ts +1 -1
- package/build-ts/server-modules/GlideFtOptions.js +5 -0
- package/build-ts/{src/server-modules → server-modules}/GlideJson.d.ts +65 -65
- package/build-ts/server-modules/GlideJson.js +1572 -0
- package/package.json +140 -64
- package/build-ts/src/Logger.d.ts +0 -32
- /package/build-ts/{src/Errors.d.ts → Errors.d.ts} +0 -0
- /package/build-ts/{src/server-modules → server-modules}/GlideFt.d.ts +0 -0
|
@@ -0,0 +1,1251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GlideClusterClient = exports.GlideClusterClientConfiguration = void 0;
|
|
7
|
+
const native_1 = require("../build-ts/native");
|
|
8
|
+
const ProtobufMessage_1 = require("../build-ts/ProtobufMessage");
|
|
9
|
+
const BaseClient_1 = require("./BaseClient");
|
|
10
|
+
const Commands_1 = require("./Commands");
|
|
11
|
+
/* eslint-disable-next-line @typescript-eslint/no-namespace */
|
|
12
|
+
var GlideClusterClientConfiguration;
|
|
13
|
+
(function (GlideClusterClientConfiguration) {
|
|
14
|
+
/**
|
|
15
|
+
* Enum representing pubsub subscription modes.
|
|
16
|
+
* @see {@link https://valkey.io/docs/topics/pubsub/|Valkey PubSub Documentation} for more details.
|
|
17
|
+
*/
|
|
18
|
+
let PubSubChannelModes;
|
|
19
|
+
(function (PubSubChannelModes) {
|
|
20
|
+
/**
|
|
21
|
+
* Use exact channel names.
|
|
22
|
+
*/
|
|
23
|
+
PubSubChannelModes[PubSubChannelModes["Exact"] = 0] = "Exact";
|
|
24
|
+
/**
|
|
25
|
+
* Use channel name patterns.
|
|
26
|
+
*/
|
|
27
|
+
PubSubChannelModes[PubSubChannelModes["Pattern"] = 1] = "Pattern";
|
|
28
|
+
/**
|
|
29
|
+
* Use sharded pubsub. Available since Valkey version 7.0.
|
|
30
|
+
*/
|
|
31
|
+
PubSubChannelModes[PubSubChannelModes["Sharded"] = 2] = "Sharded";
|
|
32
|
+
})(PubSubChannelModes = GlideClusterClientConfiguration.PubSubChannelModes || (GlideClusterClientConfiguration.PubSubChannelModes = {}));
|
|
33
|
+
})(GlideClusterClientConfiguration || (exports.GlideClusterClientConfiguration = GlideClusterClientConfiguration = {}));
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* Convert {@link ClusterGlideRecord} to {@link ClusterResponse}.
|
|
37
|
+
*
|
|
38
|
+
* @param res - Value received from Glide core.
|
|
39
|
+
* @param isRoutedToSingleNodeByDefault - Default routing policy.
|
|
40
|
+
* @param route - The route.
|
|
41
|
+
* @returns Converted value.
|
|
42
|
+
*/
|
|
43
|
+
function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
|
|
44
|
+
const isSingleNodeResponse =
|
|
45
|
+
// route not given and command is routed by default to a random node
|
|
46
|
+
(!route && isRoutedToSingleNodeByDefault) ||
|
|
47
|
+
// or route is given and it is a single node route
|
|
48
|
+
(Boolean(route) && route !== "allPrimaries" && route !== "allNodes");
|
|
49
|
+
return isSingleNodeResponse
|
|
50
|
+
? res
|
|
51
|
+
: (0, BaseClient_1.convertGlideRecordToRecord)(res);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Client used for connection to cluster servers.
|
|
55
|
+
* Use {@link createClient} to request a client.
|
|
56
|
+
*
|
|
57
|
+
* @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster | Valkey Glide Wiki}.
|
|
58
|
+
*/
|
|
59
|
+
class GlideClusterClient extends BaseClient_1.BaseClient {
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
createClientRequest(options) {
|
|
64
|
+
const configuration = super.createClientRequest(options);
|
|
65
|
+
configuration.clusterModeEnabled = true;
|
|
66
|
+
// "enabledDefaultConfigs" is the default configuration and doesn't need setting
|
|
67
|
+
if (options.periodicChecks !== undefined &&
|
|
68
|
+
options.periodicChecks !== "enabledDefaultConfigs") {
|
|
69
|
+
if (options.periodicChecks === "disabled") {
|
|
70
|
+
configuration.periodicChecksDisabled =
|
|
71
|
+
ProtobufMessage_1.connection_request.PeriodicChecksDisabled.create();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
configuration.periodicChecksManualInterval =
|
|
75
|
+
ProtobufMessage_1.connection_request.PeriodicChecksManualInterval.create({
|
|
76
|
+
durationInSec: options.periodicChecks.duration_in_sec,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.configurePubsub(options, configuration);
|
|
81
|
+
if (options.advancedConfiguration) {
|
|
82
|
+
this.configureAdvancedConfigurationBase(options.advancedConfiguration, configuration);
|
|
83
|
+
}
|
|
84
|
+
return configuration;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new `GlideClusterClient` instance and establishes connections to a Valkey Cluster.
|
|
88
|
+
*
|
|
89
|
+
* @param options - The configuration options for the client, including cluster addresses, authentication credentials, TLS settings, periodic checks, and Pub/Sub subscriptions.
|
|
90
|
+
* @returns A promise that resolves to a connected `GlideClusterClient` instance.
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* Use this static method to create and connect a `GlideClusterClient` to a Valkey Cluster.
|
|
94
|
+
* The client will automatically handle connection establishment, including cluster topology discovery and handling of authentication and TLS configurations.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Connecting to a Cluster
|
|
99
|
+
* import { GlideClusterClient, GlideClusterClientConfiguration } from '@valkey/valkey-glide';
|
|
100
|
+
*
|
|
101
|
+
* const client = await GlideClusterClient.createClient({
|
|
102
|
+
* addresses: [
|
|
103
|
+
* { host: 'address1.example.com', port: 6379 },
|
|
104
|
+
* { host: 'address2.example.com', port: 6379 },
|
|
105
|
+
* ],
|
|
106
|
+
* credentials: {
|
|
107
|
+
* username: 'user1',
|
|
108
|
+
* password: 'passwordA',
|
|
109
|
+
* },
|
|
110
|
+
* useTLS: true,
|
|
111
|
+
* periodicChecks: {
|
|
112
|
+
* duration_in_sec: 30, // Perform periodic checks every 30 seconds
|
|
113
|
+
* },
|
|
114
|
+
* pubsubSubscriptions: {
|
|
115
|
+
* channelsAndPatterns: {
|
|
116
|
+
* [GlideClusterClientConfiguration.PubSubChannelModes.Exact]: new Set(['updates']),
|
|
117
|
+
* [GlideClusterClientConfiguration.PubSubChannelModes.Sharded]: new Set(['sharded_channel']),
|
|
118
|
+
* },
|
|
119
|
+
* callback: (msg) => {
|
|
120
|
+
* console.log(`Received message: ${msg.payload}`);
|
|
121
|
+
* },
|
|
122
|
+
* },
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* - **Cluster Topology Discovery**: The client will automatically discover the cluster topology based on the seed addresses provided.
|
|
128
|
+
* - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
|
|
129
|
+
* - **TLS**: If `useTLS` is set to `true`, the client will establish secure connections using TLS.
|
|
130
|
+
* - **Periodic Checks**: The `periodicChecks` setting allows you to configure how often the client checks for cluster topology changes.
|
|
131
|
+
* - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
|
|
132
|
+
*/
|
|
133
|
+
static async createClient(options) {
|
|
134
|
+
return await super.createClientInternal(options, (socket, options) => new GlideClusterClient(socket, options));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
static async __createClient(options, connectedSocket) {
|
|
140
|
+
return super.__createClientInternal(options, connectedSocket, (socket, options) => new GlideClusterClient(socket, options));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
scanOptionsToProto(cursor, options) {
|
|
146
|
+
const command = ProtobufMessage_1.command_request.ClusterScan.create();
|
|
147
|
+
command.cursor = cursor;
|
|
148
|
+
if (options?.match) {
|
|
149
|
+
command.matchPattern =
|
|
150
|
+
typeof options.match === "string"
|
|
151
|
+
? Buffer.from(options.match)
|
|
152
|
+
: options.match;
|
|
153
|
+
}
|
|
154
|
+
if (options?.count) {
|
|
155
|
+
command.count = options.count;
|
|
156
|
+
}
|
|
157
|
+
if (options?.type) {
|
|
158
|
+
command.objectType = options.type;
|
|
159
|
+
}
|
|
160
|
+
command.allowNonCoveredSlots = options?.allowNonCoveredSlots ?? false;
|
|
161
|
+
return command;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
createClusterScanPromise(cursor, options) {
|
|
167
|
+
this.ensureClientIsOpen();
|
|
168
|
+
// separate decoder option from scan options
|
|
169
|
+
const { decoder = this.defaultDecoder, ...scanOptions } = options || {};
|
|
170
|
+
const cursorId = cursor.getCursor();
|
|
171
|
+
const command = this.scanOptionsToProto(cursorId, scanOptions);
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
const callbackIdx = this.getCallbackIndex();
|
|
174
|
+
this.promiseCallbackFunctions[callbackIdx] = [
|
|
175
|
+
(resolveAns) => {
|
|
176
|
+
try {
|
|
177
|
+
resolve([
|
|
178
|
+
new native_1.ClusterScanCursor(resolveAns[0].toString()),
|
|
179
|
+
resolveAns[1],
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
reject(error);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
reject,
|
|
187
|
+
decoder,
|
|
188
|
+
];
|
|
189
|
+
this.writeOrBufferRequest(new ProtobufMessage_1.command_request.CommandRequest({
|
|
190
|
+
callbackIdx,
|
|
191
|
+
clusterScan: command,
|
|
192
|
+
}), (message, writer) => {
|
|
193
|
+
ProtobufMessage_1.command_request.CommandRequest.encodeDelimited(message, writer);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Incrementally iterates over the keys in the Cluster.
|
|
199
|
+
*
|
|
200
|
+
* This command is similar to the `SCAN` command but designed for Cluster environments.
|
|
201
|
+
* It uses a {@link ClusterScanCursor} object to manage iterations.
|
|
202
|
+
*
|
|
203
|
+
* For each iteration, use the new cursor object to continue the scan.
|
|
204
|
+
* Using the same cursor object for multiple iterations may result in unexpected behavior.
|
|
205
|
+
*
|
|
206
|
+
* For more information about the Cluster Scan implementation, see
|
|
207
|
+
* {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#cluster-scan | Cluster Scan}.
|
|
208
|
+
*
|
|
209
|
+
* This method can iterate over all keys in the database from the start of the scan until it ends.
|
|
210
|
+
* The same key may be returned in multiple scan iterations.
|
|
211
|
+
* The API does not accept `route` as it go through all slots in the cluster.
|
|
212
|
+
*
|
|
213
|
+
* @see {@link https://valkey.io/commands/scan/ | valkey.io} for more details.
|
|
214
|
+
*
|
|
215
|
+
* @param cursor - The cursor object that wraps the scan state.
|
|
216
|
+
* To start a new scan, create a new empty `ClusterScanCursor` using {@link ClusterScanCursor}.
|
|
217
|
+
* @param options - (Optional) The scan options, see {@link ClusterScanOptions} and {@link DecoderOption}.
|
|
218
|
+
* @returns A Promise resolving to an array containing the next cursor and an array of keys,
|
|
219
|
+
* formatted as [`ClusterScanCursor`, `string[]`].
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Iterate over all keys in the cluster
|
|
224
|
+
* await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "key3", value: "value3"}]);
|
|
225
|
+
* let cursor = new ClusterScanCursor();
|
|
226
|
+
* const allKeys: GlideString[] = [];
|
|
227
|
+
* let keys: GlideString[] = [];
|
|
228
|
+
* while (!cursor.isFinished()) {
|
|
229
|
+
* [cursor, keys] = await client.scan(cursor, { count: 10 });
|
|
230
|
+
* allKeys.push(...keys);
|
|
231
|
+
* }
|
|
232
|
+
* console.log(allKeys); // ["key1", "key2", "key3"]
|
|
233
|
+
*
|
|
234
|
+
* // Iterate over keys matching a pattern
|
|
235
|
+
* await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "notMyKey", value: "value3"}, {key: "somethingElse", value: "value4"}]);
|
|
236
|
+
* let cursor = new ClusterScanCursor();
|
|
237
|
+
* const matchedKeys: GlideString[] = [];
|
|
238
|
+
* while (!cursor.isFinished()) {
|
|
239
|
+
* const [cursor, keys] = await client.scan(cursor, { match: "*key*", count: 10 });
|
|
240
|
+
* matchedKeys.push(...keys);
|
|
241
|
+
* }
|
|
242
|
+
* console.log(matchedKeys); // ["key1", "key2", "notMyKey"]
|
|
243
|
+
*
|
|
244
|
+
* // Iterate over keys of a specific type
|
|
245
|
+
* await client.mset([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {key: "key3", value: "value3"}]);
|
|
246
|
+
* await client.sadd("thisIsASet", ["value4"]);
|
|
247
|
+
* let cursor = new ClusterScanCursor();
|
|
248
|
+
* const stringKeys: GlideString[] = [];
|
|
249
|
+
* while (!cursor.isFinished()) {
|
|
250
|
+
* const [cursor, keys] = await client.scan(cursor, { type: object.STRING });
|
|
251
|
+
* stringKeys.push(...keys);
|
|
252
|
+
* }
|
|
253
|
+
* console.log(stringKeys); // ["key1", "key2", "key3"]
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
async scan(cursor, options) {
|
|
257
|
+
return this.createClusterScanPromise(cursor, options);
|
|
258
|
+
}
|
|
259
|
+
/** Executes a single command, without checking inputs. Every part of the command, including subcommands,
|
|
260
|
+
* should be added as a separate value in args.
|
|
261
|
+
* The command will be routed automatically based on the passed command's default request policy, unless `route` is provided,
|
|
262
|
+
* in which case the client will route the command to the nodes defined by `route`.
|
|
263
|
+
*
|
|
264
|
+
* Note: An error will occur if the string decoder is used with commands that return only bytes as a response.
|
|
265
|
+
*
|
|
266
|
+
* @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.
|
|
267
|
+
*
|
|
268
|
+
* @param args - A list including the command name and arguments for the custom command.
|
|
269
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}
|
|
270
|
+
* @returns The executed custom command return value.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* // Example usage of customCommand method to retrieve pub/sub clients with routing to all primary nodes
|
|
275
|
+
* const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"], {route: "allPrimaries", decoder: Decoder.String});
|
|
276
|
+
* console.log(result); // Output: Returns a list of all pub/sub clients
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
async customCommand(args, options) {
|
|
280
|
+
const command = (0, Commands_1.createCustomCommand)(args);
|
|
281
|
+
return super.createWritePromise(command, options);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Executes a batch by processing the queued commands.
|
|
285
|
+
*
|
|
286
|
+
* **Routing Behavior:**
|
|
287
|
+
*
|
|
288
|
+
* - If a `route` is specified in {@link ClusterBatchOptions}, the entire batch is sent to the specified node.
|
|
289
|
+
* - If no `route` is specified:
|
|
290
|
+
* - **Atomic batches (Transactions):** Routed to the slot owner of the first key in the batch. If no key is found, the request is sent to a random node.
|
|
291
|
+
* - **Non-atomic batches (Pipelines):** Each command is routed to the node owning the corresponding key's slot. If no key is present, routing follows the command's request policy. Multi-node commands are automatically split and dispatched to the appropriate nodes.
|
|
292
|
+
*
|
|
293
|
+
* **Behavior Notes:**
|
|
294
|
+
*
|
|
295
|
+
* - **Atomic Batches (Transactions):** All key-based commands must map to the same hash slot. If keys span different slots, the transaction will fail. If the transaction fails due to a `WATCH` command, `exec` will return `null`.
|
|
296
|
+
*
|
|
297
|
+
* @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
|
|
298
|
+
*
|
|
299
|
+
* **Retry and Redirection:**
|
|
300
|
+
*
|
|
301
|
+
* - If a redirection error occurs:
|
|
302
|
+
* - **Atomic batches (Transactions):** The entire transaction will be redirected.
|
|
303
|
+
* - **Non-atomic batches (Pipelines):** Only commands that encountered redirection errors will be retried.
|
|
304
|
+
* - Retries for failures will be handled according to the configured {@link BatchRetryStrategy}.
|
|
305
|
+
*
|
|
306
|
+
* @param batch - A {@link ClusterBatch} containing the commands to execute.
|
|
307
|
+
* @param raiseOnError - Determines how errors are handled within the batch response.
|
|
308
|
+
* - If `true`, the first encountered error in the batch will be raised as an exception of type {@link RequestError}
|
|
309
|
+
* after all retries and reconnections have been exhausted.
|
|
310
|
+
* - If `false`, errors will be included as part of the batch response, allowing the caller to process both successful and failed commands together.
|
|
311
|
+
* In this case, error details will be provided as instances of {@link RequestError} in the response list.
|
|
312
|
+
* @param options - (Optional) {@link ClusterBatchOptions} and {@link DecoderOption} specifying execution and decoding behavior.
|
|
313
|
+
* @returns A Promise resolving to an array of results, where each entry corresponds to a command’s execution result.
|
|
314
|
+
* - If the transaction fails due to a `WATCH` command, the promise resolves to `null`.
|
|
315
|
+
*
|
|
316
|
+
* @see {@link https://valkey.io/docs/topics/transactions/|Valkey Transactions (Atomic Batches)}
|
|
317
|
+
* @see {@link https://valkey.io/docs/topics/pipelining/|Valkey Pipelines (Non-Atomic Batches)}
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* // Atomic batch (transaction): all keys must share the same hash slot
|
|
321
|
+
* const atomicBatch = new ClusterBatch(true)
|
|
322
|
+
* .set('key', '1')
|
|
323
|
+
* .incr('key')
|
|
324
|
+
* .get('key');
|
|
325
|
+
*
|
|
326
|
+
* const atomicOptions = {timeout: 1000};
|
|
327
|
+
* const atomicResult = await clusterClient.exec(atomicBatch, false, atomicOptions);
|
|
328
|
+
* console.log('Atomic Batch Result:', atomicResult);
|
|
329
|
+
* // Output: ['OK', 2, '2']
|
|
330
|
+
*
|
|
331
|
+
* // Non-atomic batch (pipeline): keys may span different hash slots
|
|
332
|
+
* const nonAtomicBatch = new ClusterBatch(false)
|
|
333
|
+
* .set('key1', 'value1')
|
|
334
|
+
* .set('key2', 'value2')
|
|
335
|
+
* .get('key1')
|
|
336
|
+
* .get('key2');
|
|
337
|
+
*
|
|
338
|
+
* const pipelineOptions = { retryStrategy: { retryServerError: true, retryConnectionError: false } };
|
|
339
|
+
* const nonAtomicResult = await clusterClient.exec(nonAtomicBatch, false, pipelineOptions);
|
|
340
|
+
* console.log(nonAtomicResult);
|
|
341
|
+
* // Output: ['OK', 'OK', 'value1', 'value2']
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
async exec(batch, raiseOnError, options) {
|
|
345
|
+
return this.createWritePromise(batch.commands, options, batch.isAtomic, raiseOnError).then((result) => this.processResultWithSetCommands(result, batch.setCommandsIndexes));
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Pings the server.
|
|
349
|
+
*
|
|
350
|
+
* The command will be routed to all primary nodes, unless `route` is provided.
|
|
351
|
+
*
|
|
352
|
+
* @see {@link https://valkey.io/commands/ping/|valkey.io} for details.
|
|
353
|
+
*
|
|
354
|
+
* @param options - (Optional) Additional parameters:
|
|
355
|
+
* - (Optional) `message` : a message to include in the `PING` command.
|
|
356
|
+
* + If not provided, the server will respond with `"PONG"`.
|
|
357
|
+
* + If provided, the server will respond with a copy of the message.
|
|
358
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
359
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
360
|
+
* @returns `"PONG"` if `message` is not provided, otherwise return a copy of `message`.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* // Example usage of ping method without any message
|
|
365
|
+
* const result = await client.ping();
|
|
366
|
+
* console.log(result); // Output: 'PONG'
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* // Example usage of ping method with a message
|
|
372
|
+
* const result = await client.ping("Hello");
|
|
373
|
+
* console.log(result); // Output: 'Hello'
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
async ping(options) {
|
|
377
|
+
return this.createWritePromise((0, Commands_1.createPing)(options?.message), options);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Gets information and statistics about the server.
|
|
381
|
+
*
|
|
382
|
+
* The command will be routed to all primary nodes, unless `route` is provided.
|
|
383
|
+
*
|
|
384
|
+
* Starting from server version 7, command supports multiple section arguments.
|
|
385
|
+
*
|
|
386
|
+
* @see {@link https://valkey.io/commands/info/|valkey.io} for details.
|
|
387
|
+
*
|
|
388
|
+
* @param options - (Optional) Additional parameters:
|
|
389
|
+
* - (Optional) `sections`: a list of {@link InfoOptions} values specifying which sections of information to retrieve.
|
|
390
|
+
* When no parameter is provided, {@link InfoOptions.Default|Default} is assumed.
|
|
391
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
392
|
+
* @returns A string containing the information for the sections requested.
|
|
393
|
+
* When specifying a route other than a single node,
|
|
394
|
+
* it returns a dictionary where each address is the key and its corresponding node response is the value.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* // Example usage of the info method with retrieving total_net_input_bytes from the result
|
|
399
|
+
* const result = await client.info(new Section[] { Section.STATS });
|
|
400
|
+
* console.log(someClusterParsingFunction(result, "total_net_input_bytes")); // Output: 1
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
async info(options) {
|
|
404
|
+
return this.createWritePromise((0, Commands_1.createInfo)(options?.sections), { decoder: BaseClient_1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Gets the name of the connection to which the request is routed.
|
|
408
|
+
*
|
|
409
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
410
|
+
*
|
|
411
|
+
* @see {@link https://valkey.io/commands/client-getname/|valkey.io} for details.
|
|
412
|
+
*
|
|
413
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
414
|
+
*
|
|
415
|
+
* @returns - The name of the client connection as a string if a name is set, or `null` if no name is assigned.
|
|
416
|
+
* When specifying a route other than a single node, it returns a dictionary where each address is the key and
|
|
417
|
+
* its corresponding node response is the value.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```typescript
|
|
421
|
+
* // Example usage of client_getname method
|
|
422
|
+
* const result = await client.client_getname();
|
|
423
|
+
* console.log(result); // Output: 'Connection Name'
|
|
424
|
+
* ```
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* // Example usage of clientGetName method with routing to all nodes
|
|
429
|
+
* const result = await client.clientGetName('allNodes');
|
|
430
|
+
* console.log(result); // Output: {'addr': 'Connection Name', 'addr2': 'Connection Name', 'addr3': 'Connection Name'}
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
async clientGetName(options) {
|
|
434
|
+
return this.createWritePromise((0, Commands_1.createClientGetName)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Rewrites the configuration file with the current configuration.
|
|
438
|
+
*
|
|
439
|
+
* The command will be routed to a all nodes, unless `route` is provided.
|
|
440
|
+
*
|
|
441
|
+
* @see {@link https://valkey.io/commands/config-rewrite/|valkey.io} for details.
|
|
442
|
+
*
|
|
443
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
444
|
+
* @returns `"OK"` when the configuration was rewritten properly. Otherwise, an error is thrown.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* // Example usage of configRewrite command
|
|
449
|
+
* const result = await client.configRewrite();
|
|
450
|
+
* console.log(result); // Output: 'OK'
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
async configRewrite(options) {
|
|
454
|
+
return this.createWritePromise((0, Commands_1.createConfigRewrite)(), {
|
|
455
|
+
decoder: BaseClient_1.Decoder.String,
|
|
456
|
+
...options,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Resets the statistics reported by the server using the `INFO` and `LATENCY HISTOGRAM` commands.
|
|
461
|
+
*
|
|
462
|
+
* The command will be routed to all nodes, unless `route` is provided.
|
|
463
|
+
*
|
|
464
|
+
* @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details.
|
|
465
|
+
*
|
|
466
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
467
|
+
* @returns always `"OK"`.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* // Example usage of configResetStat command
|
|
472
|
+
* const result = await client.configResetStat();
|
|
473
|
+
* console.log(result); // Output: 'OK'
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
async configResetStat(options) {
|
|
477
|
+
return this.createWritePromise((0, Commands_1.createConfigResetStat)(), {
|
|
478
|
+
decoder: BaseClient_1.Decoder.String,
|
|
479
|
+
...options,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Returns the current connection ID.
|
|
484
|
+
*
|
|
485
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
486
|
+
*
|
|
487
|
+
* @see {@link https://valkey.io/commands/client-id/|valkey.io} for details.
|
|
488
|
+
*
|
|
489
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
490
|
+
* @returns The ID of the connection. When specifying a route other than a single node,
|
|
491
|
+
* it returns a dictionary where each address is the key and its corresponding node response is the value.
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* const result = await client.clientId();
|
|
496
|
+
* console.log("Connection id: " + result);
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
async clientId(options) {
|
|
500
|
+
return this.createWritePromise((0, Commands_1.createClientId)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Reads the configuration parameters of the running server.
|
|
504
|
+
* Starting from server version 7, command supports multiple parameters.
|
|
505
|
+
*
|
|
506
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
507
|
+
*
|
|
508
|
+
* @see {@link https://valkey.io/commands/config-get/|valkey.io} for details.
|
|
509
|
+
*
|
|
510
|
+
* @param parameters - A list of configuration parameter names to retrieve values for.
|
|
511
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
512
|
+
*
|
|
513
|
+
* @returns A map of values corresponding to the configuration parameters. When specifying a route other than a single node,
|
|
514
|
+
* it returns a dictionary where each address is the key and its corresponding node response is the value.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* // Example usage of config_get method with a single configuration parameter with routing to a random node
|
|
519
|
+
* const result = await client.config_get(["timeout"], "randomNode");
|
|
520
|
+
* console.log(result); // Output: {'timeout': '1000'}
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```typescript
|
|
525
|
+
* // Example usage of configGet method with multiple configuration parameters
|
|
526
|
+
* const result = await client.configGet(["timeout", "maxmemory"]);
|
|
527
|
+
* console.log(result); // Output: {'timeout': '1000', 'maxmemory': '1GB'}
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
async configGet(parameters, options) {
|
|
531
|
+
return this.createWritePromise((0, Commands_1.createConfigGet)(parameters), options).then((res) => (0, BaseClient_1.convertGlideRecordToRecord)(res));
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Sets configuration parameters to the specified values.
|
|
535
|
+
* Starting from server version 7, command supports multiple parameters.
|
|
536
|
+
*
|
|
537
|
+
* The command will be routed to all nodes, unless `route` is provided.
|
|
538
|
+
*
|
|
539
|
+
* @see {@link https://valkey.io/commands/config-set/|valkey.io} for details.
|
|
540
|
+
*
|
|
541
|
+
* @param parameters - A map consisting of configuration parameters and their respective values to set.
|
|
542
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
543
|
+
* @returns "OK" when the configuration was set properly. Otherwise an error is thrown.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* // Example usage of configSet method to set multiple configuration parameters
|
|
548
|
+
* const result = await client.configSet({ timeout: "1000", maxmemory: "1GB" });
|
|
549
|
+
* console.log(result); // Output: 'OK'
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
async configSet(parameters, options) {
|
|
553
|
+
return this.createWritePromise((0, Commands_1.createConfigSet)(parameters), {
|
|
554
|
+
decoder: BaseClient_1.Decoder.String,
|
|
555
|
+
...options,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Echoes the provided `message` back.
|
|
560
|
+
*
|
|
561
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
562
|
+
*
|
|
563
|
+
* @see {@link https://valkey.io/commands/echo/|valkey.io} for details.
|
|
564
|
+
*
|
|
565
|
+
* @param message - The message to be echoed back.
|
|
566
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
567
|
+
* @returns The provided `message`. When specifying a route other than a single node,
|
|
568
|
+
* it returns a dictionary where each address is the key and its corresponding node response is the value.
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* // Example usage of the echo command
|
|
573
|
+
* const echoedMessage = await client.echo("valkey-glide");
|
|
574
|
+
* console.log(echoedMessage); // Output: "valkey-glide"
|
|
575
|
+
* ```
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* // Example usage of the echo command with routing to all nodes
|
|
579
|
+
* const echoedMessage = await client.echo("valkey-glide", "allNodes");
|
|
580
|
+
* console.log(echoedMessage); // Output: {'addr': 'valkey-glide', 'addr2': 'valkey-glide', 'addr3': 'valkey-glide'}
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
async echo(message, options) {
|
|
584
|
+
return this.createWritePromise((0, Commands_1.createEcho)(message), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Returns the server time.
|
|
588
|
+
*
|
|
589
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
590
|
+
*
|
|
591
|
+
* @see {@link https://valkey.io/commands/time/|valkey.io} for details.
|
|
592
|
+
*
|
|
593
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
594
|
+
*
|
|
595
|
+
* @returns The current server time as an `array` with two items:
|
|
596
|
+
* - A Unix timestamp,
|
|
597
|
+
* - The amount of microseconds already elapsed in the current second.
|
|
598
|
+
*
|
|
599
|
+
* When specifying a route other than a single node, it returns a dictionary where each address is the key and
|
|
600
|
+
* its corresponding node response is the value.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```typescript
|
|
604
|
+
* // Example usage of time method without any argument
|
|
605
|
+
* const result = await client.time();
|
|
606
|
+
* console.log(result); // Output: ['1710925775', '913580']
|
|
607
|
+
* ```
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* // Example usage of time method with routing to all nodes
|
|
612
|
+
* const result = await client.time('allNodes');
|
|
613
|
+
* console.log(result); // Output: {'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']}
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
async time(options) {
|
|
617
|
+
return this.createWritePromise((0, Commands_1.createTime)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Copies the value stored at the `source` to the `destination` key. When `replace` is `true`,
|
|
621
|
+
* removes the `destination` key first if it already exists, otherwise performs no action.
|
|
622
|
+
*
|
|
623
|
+
* @see {@link https://valkey.io/commands/copy/|valkey.io} for details.
|
|
624
|
+
* @remarks When in cluster mode, `source` and `destination` must map to the same hash slot.
|
|
625
|
+
* @remarks Since Valkey version 6.2.0.
|
|
626
|
+
*
|
|
627
|
+
* @param source - The key to the source value.
|
|
628
|
+
* @param destination - The key where the value should be copied to.
|
|
629
|
+
* @param options - (Optional) Additional parameters:
|
|
630
|
+
* - (Optional) `replace`: if `true`, the `destination` key should be removed before copying the
|
|
631
|
+
* value to it. If not provided, no action will be performed if the key already exists.
|
|
632
|
+
* @returns `true` if `source` was copied, `false` if the `source` was not copied.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* ```typescript
|
|
636
|
+
* const result = await client.copy("set1", "set2", { replace: true });
|
|
637
|
+
* console.log(result); // Output: true - "set1" was copied to "set2".
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
async copy(source, destination, options) {
|
|
641
|
+
return this.createWritePromise((0, Commands_1.createCopy)(source, destination, options));
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Displays a piece of generative computer art and the server version.
|
|
645
|
+
*
|
|
646
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
647
|
+
*
|
|
648
|
+
* @see {@link https://valkey.io/commands/lolwut/|valkey.io} for details.
|
|
649
|
+
*
|
|
650
|
+
* @param options - (Optional) The LOLWUT options - see {@link LolwutOptions} and {@link RouteOption}.
|
|
651
|
+
* @returns A piece of generative computer art along with the current server version.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```typescript
|
|
655
|
+
* const response = await client.lolwut({ version: 6, parameters: [40, 20] }, "allNodes");
|
|
656
|
+
* console.log(response); // Output: "Valkey ver. 7.2.3" - Indicates the current server version.
|
|
657
|
+
* ```
|
|
658
|
+
*/
|
|
659
|
+
async lolwut(options) {
|
|
660
|
+
return this.createWritePromise((0, Commands_1.createLolwut)(options), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Invokes a previously loaded function.
|
|
664
|
+
*
|
|
665
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
666
|
+
*
|
|
667
|
+
* @see {@link https://valkey.io/commands/fcall/|valkey.io} for details.
|
|
668
|
+
* @remarks Since Valkey version 7.0.0.
|
|
669
|
+
*
|
|
670
|
+
* @param func - The function name.
|
|
671
|
+
* @param args - A list of `function` arguments and it should not represent names of keys.
|
|
672
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
673
|
+
* @returns The invoked function's return value.
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```typescript
|
|
677
|
+
* const response = await client.fcallWithRoute("Deep_Thought", [], "randomNode");
|
|
678
|
+
* console.log(response); // Output: Returns the function's return value.
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
async fcallWithRoute(func, args, options) {
|
|
682
|
+
return this.createWritePromise((0, Commands_1.createFCall)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Invokes a previously loaded read-only function.
|
|
686
|
+
*
|
|
687
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
688
|
+
*
|
|
689
|
+
* @see {@link https://valkey.io/commands/fcall/|valkey.io} for details.
|
|
690
|
+
* @remarks Since Valkey version 7.0.0.
|
|
691
|
+
*
|
|
692
|
+
* @param func - The function name.
|
|
693
|
+
* @param args - A list of `function` arguments and it should not represent names of keys.
|
|
694
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
695
|
+
* @returns The invoked function's return value.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```typescript
|
|
699
|
+
* const response = await client.fcallReadonlyWithRoute("Deep_Thought", ["Answer", "to", "the", "Ultimate",
|
|
700
|
+
* "Question", "of", "Life,", "the", "Universe,", "and", "Everything"], "randomNode");
|
|
701
|
+
* console.log(response); // Output: 42 # The return value on the function that was execute.
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
async fcallReadonlyWithRoute(func, args, options) {
|
|
705
|
+
return this.createWritePromise((0, Commands_1.createFCallReadOnly)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Deletes a library and all its functions.
|
|
709
|
+
*
|
|
710
|
+
* @see {@link https://valkey.io/commands/function-delete/|valkey.io} for details.
|
|
711
|
+
* @remarks Since Valkey version 7.0.0.
|
|
712
|
+
*
|
|
713
|
+
* @param libraryCode - The library name to delete.
|
|
714
|
+
* @param route - (Optional) The command will be routed to all primary node, unless `route` is provided, in which
|
|
715
|
+
* case the client will route the command to the nodes defined by `route`.
|
|
716
|
+
* @returns A simple `"OK"` response.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```typescript
|
|
720
|
+
* const result = await client.functionDelete("libName");
|
|
721
|
+
* console.log(result); // Output: 'OK'
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
async functionDelete(libraryCode, options) {
|
|
725
|
+
return this.createWritePromise((0, Commands_1.createFunctionDelete)(libraryCode), {
|
|
726
|
+
decoder: BaseClient_1.Decoder.String,
|
|
727
|
+
...options,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Loads a library to Valkey.
|
|
732
|
+
*
|
|
733
|
+
* @see {@link https://valkey.io/commands/function-load/|valkey.io} for details.
|
|
734
|
+
* @remarks Since Valkey version 7.0.0.
|
|
735
|
+
*
|
|
736
|
+
* @param libraryCode - The source code that implements the library.
|
|
737
|
+
* @param options - (Optional) Additional parameters:
|
|
738
|
+
* - (Optional) `replace`: whether the given library should overwrite a library with the same name if it
|
|
739
|
+
* already exists.
|
|
740
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
741
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
742
|
+
* @returns The library name that was loaded.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* const code = "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)";
|
|
747
|
+
* const result = await client.functionLoad(code, { replace: true, route: 'allNodes' });
|
|
748
|
+
* console.log(result); // Output: 'mylib'
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
async functionLoad(libraryCode, options) {
|
|
752
|
+
return this.createWritePromise((0, Commands_1.createFunctionLoad)(libraryCode, options?.replace), options);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Deletes all function libraries.
|
|
756
|
+
*
|
|
757
|
+
* @see {@link https://valkey.io/commands/function-flush/|valkey.io} for details.
|
|
758
|
+
* @remarks Since Valkey version 7.0.0.
|
|
759
|
+
*
|
|
760
|
+
* @param options - (Optional) Additional parameters:
|
|
761
|
+
* - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
762
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
763
|
+
* @returns A simple `"OK"` response.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```typescript
|
|
767
|
+
* const result = await client.functionFlush(FlushMode.SYNC);
|
|
768
|
+
* console.log(result); // Output: 'OK'
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
771
|
+
async functionFlush(options) {
|
|
772
|
+
return this.createWritePromise((0, Commands_1.createFunctionFlush)(options?.mode), {
|
|
773
|
+
decoder: BaseClient_1.Decoder.String,
|
|
774
|
+
...options,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Returns information about the functions and libraries.
|
|
779
|
+
*
|
|
780
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
781
|
+
*
|
|
782
|
+
* @see {@link https://valkey.io/commands/function-list/|valkey.io} for details.
|
|
783
|
+
* @remarks Since Valkey version 7.0.0.
|
|
784
|
+
*
|
|
785
|
+
* @param options - (Optional) See {@link FunctionListOptions}, {@link DecoderOption}, and {@link RouteOption}.
|
|
786
|
+
* @returns Info about all or selected libraries and their functions in {@link FunctionListResponse} format.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```typescript
|
|
790
|
+
* // Request info for specific library including the source code
|
|
791
|
+
* const result1 = await client.functionList({ libNamePattern: "myLib*", withCode: true });
|
|
792
|
+
* // Request info for all libraries
|
|
793
|
+
* const result2 = await client.functionList();
|
|
794
|
+
* console.log(result2); // Output:
|
|
795
|
+
* // [{
|
|
796
|
+
* // "library_name": "myLib5_backup",
|
|
797
|
+
* // "engine": "LUA",
|
|
798
|
+
* // "functions": [{
|
|
799
|
+
* // "name": "myfunc",
|
|
800
|
+
* // "description": null,
|
|
801
|
+
* // "flags": [ "no-writes" ],
|
|
802
|
+
* // }],
|
|
803
|
+
* // "library_code": "#!lua name=myLib5_backup \n redis.register_function('myfunc', function(keys, args) return args[1] end)"
|
|
804
|
+
* // }]
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
async functionList(options) {
|
|
808
|
+
return this.createWritePromise((0, Commands_1.createFunctionList)(options), options).then((res) => res.length == 0
|
|
809
|
+
? res // no libs
|
|
810
|
+
: (Array.isArray(res[0])
|
|
811
|
+
? // single node response
|
|
812
|
+
res.map(BaseClient_1.convertGlideRecordToRecord)
|
|
813
|
+
: // multi node response
|
|
814
|
+
(0, BaseClient_1.convertGlideRecordToRecord)(res)));
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Returns information about the function that's currently running and information about the
|
|
818
|
+
* available execution engines.
|
|
819
|
+
*
|
|
820
|
+
* The command will be routed to all nodes, unless `route` is provided.
|
|
821
|
+
*
|
|
822
|
+
* @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details.
|
|
823
|
+
* @remarks Since Valkey version 7.0.0.
|
|
824
|
+
*
|
|
825
|
+
* @param options - (Optional) See {@link DecoderOption} and {@link RouteOption}.
|
|
826
|
+
* @returns A `Record` with two keys:
|
|
827
|
+
* - `"running_script"` with information about the running script.
|
|
828
|
+
* - `"engines"` with information about available engines and their stats.
|
|
829
|
+
* - See example for more details.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* const response = await client.functionStats("randomNode");
|
|
834
|
+
* console.log(response); // Output:
|
|
835
|
+
* // {
|
|
836
|
+
* // "running_script":
|
|
837
|
+
* // {
|
|
838
|
+
* // "name": "deep_thought",
|
|
839
|
+
* // "command": ["fcall", "deep_thought", "0"],
|
|
840
|
+
* // "duration_ms": 5008
|
|
841
|
+
* // },
|
|
842
|
+
* // "engines":
|
|
843
|
+
* // {
|
|
844
|
+
* // "LUA":
|
|
845
|
+
* // {
|
|
846
|
+
* // "libraries_count": 2,
|
|
847
|
+
* // "functions_count": 3
|
|
848
|
+
* // }
|
|
849
|
+
* // }
|
|
850
|
+
* // }
|
|
851
|
+
* // Output if no scripts running:
|
|
852
|
+
* // {
|
|
853
|
+
* // "running_script": null
|
|
854
|
+
* // "engines":
|
|
855
|
+
* // {
|
|
856
|
+
* // "LUA":
|
|
857
|
+
* // {
|
|
858
|
+
* // "libraries_count": 2,
|
|
859
|
+
* // "functions_count": 3
|
|
860
|
+
* // }
|
|
861
|
+
* // }
|
|
862
|
+
* // }
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
865
|
+
async functionStats(options) {
|
|
866
|
+
return this.createWritePromise((0, Commands_1.createFunctionStats)(), options).then((res) => (0, BaseClient_1.convertGlideRecordToRecord)(res));
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Kills a function that is currently executing.
|
|
870
|
+
* `FUNCTION KILL` terminates read-only functions only.
|
|
871
|
+
*
|
|
872
|
+
* @see {@link https://valkey.io/commands/function-kill/|valkey.io} for details.
|
|
873
|
+
* @remarks Since Valkey version 7.0.0.
|
|
874
|
+
*
|
|
875
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
876
|
+
* @returns `"OK"` if function is terminated. Otherwise, throws an error.
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
879
|
+
* ```typescript
|
|
880
|
+
* await client.functionKill();
|
|
881
|
+
* ```
|
|
882
|
+
*/
|
|
883
|
+
async functionKill(options) {
|
|
884
|
+
return this.createWritePromise((0, Commands_1.createFunctionKill)(), {
|
|
885
|
+
decoder: BaseClient_1.Decoder.String,
|
|
886
|
+
...options,
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Returns the serialized payload of all loaded libraries.
|
|
891
|
+
*
|
|
892
|
+
* @see {@link https://valkey.io/commands/function-dump/|valkey.io} for details.
|
|
893
|
+
* @remarks Since Valkey version 7.0.0.
|
|
894
|
+
*
|
|
895
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
896
|
+
* @returns The serialized payload of all loaded libraries.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```typescript
|
|
900
|
+
* const data = await client.functionDump();
|
|
901
|
+
* // data can be used to restore loaded functions on any Valkey instance
|
|
902
|
+
* ```
|
|
903
|
+
*/
|
|
904
|
+
async functionDump(options) {
|
|
905
|
+
return this.createWritePromise((0, Commands_1.createFunctionDump)(), { decoder: BaseClient_1.Decoder.Bytes, ...options }).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Restores libraries from the serialized payload returned by {@link functionDump}.
|
|
909
|
+
*
|
|
910
|
+
* @see {@link https://valkey.io/commands/function-restore/|valkey.io} for details.
|
|
911
|
+
* @remarks Since Valkey version 7.0.0.
|
|
912
|
+
*
|
|
913
|
+
* @param payload - The serialized data from {@link functionDump}.
|
|
914
|
+
* @param options - (Optional) Additional parameters:
|
|
915
|
+
* - (Optional) `policy`: a policy for handling existing libraries, see {@link FunctionRestorePolicy}.
|
|
916
|
+
* {@link FunctionRestorePolicy.APPEND} is used by default.
|
|
917
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
918
|
+
* @returns `"OK"`.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```typescript
|
|
922
|
+
* await client.functionRestore(data, { policy: FunctionRestorePolicy.FLUSH, route: "allPrimaries" });
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
async functionRestore(payload, options) {
|
|
926
|
+
return this.createWritePromise((0, Commands_1.createFunctionRestore)(payload, options?.policy), { decoder: BaseClient_1.Decoder.String, ...options });
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Deletes all the keys of all the existing databases. This command never fails.
|
|
930
|
+
*
|
|
931
|
+
* The command will be routed to all primary nodes, unless `route` is provided.
|
|
932
|
+
*
|
|
933
|
+
* @see {@link https://valkey.io/commands/flushall/|valkey.io} for details.
|
|
934
|
+
*
|
|
935
|
+
* @param options - (Optional) Additional parameters:
|
|
936
|
+
* - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
937
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
938
|
+
* @returns `OK`.
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```typescript
|
|
942
|
+
* const result = await client.flushall(FlushMode.SYNC);
|
|
943
|
+
* console.log(result); // Output: 'OK'
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
async flushall(options) {
|
|
947
|
+
return this.createWritePromise((0, Commands_1.createFlushAll)(options?.mode), {
|
|
948
|
+
decoder: BaseClient_1.Decoder.String,
|
|
949
|
+
...options,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Deletes all the keys of the currently selected database. This command never fails.
|
|
954
|
+
*
|
|
955
|
+
* The command will be routed to all primary nodes, unless `route` is provided.
|
|
956
|
+
*
|
|
957
|
+
* @see {@link https://valkey.io/commands/flushdb/|valkey.io} for details.
|
|
958
|
+
*
|
|
959
|
+
* @param options - (Optional) Additional parameters:
|
|
960
|
+
* - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
961
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
962
|
+
* @returns `OK`.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* const result = await client.flushdb(FlushMode.SYNC);
|
|
967
|
+
* console.log(result); // Output: 'OK'
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
async flushdb(options) {
|
|
971
|
+
return this.createWritePromise((0, Commands_1.createFlushDB)(options?.mode), {
|
|
972
|
+
decoder: BaseClient_1.Decoder.String,
|
|
973
|
+
...options,
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Returns the number of keys in the database.
|
|
978
|
+
*
|
|
979
|
+
* The command will be routed to all nodes, unless `route` is provided.
|
|
980
|
+
*
|
|
981
|
+
* @see {@link https://valkey.io/commands/dbsize/|valkey.io} for details.
|
|
982
|
+
*
|
|
983
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
984
|
+
* @returns The number of keys in the database.
|
|
985
|
+
* In the case of routing the query to multiple nodes, returns the aggregated number of keys across the different nodes.
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
* ```typescript
|
|
989
|
+
* const numKeys = await client.dbsize("allPrimaries");
|
|
990
|
+
* console.log("Number of keys across all primary nodes: ", numKeys);
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
async dbsize(options) {
|
|
994
|
+
return this.createWritePromise((0, Commands_1.createDBSize)(), options);
|
|
995
|
+
}
|
|
996
|
+
/** Publish a message on pubsub channel.
|
|
997
|
+
* This command aggregates PUBLISH and SPUBLISH commands functionalities.
|
|
998
|
+
* The mode is selected using the 'sharded' parameter.
|
|
999
|
+
* For both sharded and non-sharded mode, request is routed using hashed channel as key.
|
|
1000
|
+
*
|
|
1001
|
+
* @see {@link https://valkey.io/commands/publish} and {@link https://valkey.io/commands/spublish} for more details.
|
|
1002
|
+
*
|
|
1003
|
+
* @param message - Message to publish.
|
|
1004
|
+
* @param channel - Channel to publish the message on.
|
|
1005
|
+
* @param sharded - Use sharded pubsub mode. Available since Valkey version 7.0.
|
|
1006
|
+
* @returns - Number of subscriptions in primary node that received the message.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* // Example usage of publish command
|
|
1011
|
+
* const result = await client.publish("Hi all!", "global-channel");
|
|
1012
|
+
* console.log(result); // Output: 1 - This message was posted to 1 subscription which is configured on primary node
|
|
1013
|
+
* ```
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```typescript
|
|
1017
|
+
* // Example usage of spublish command
|
|
1018
|
+
* const result = await client.publish("Hi all!", "global-channel", true);
|
|
1019
|
+
* console.log(result); // Output: 2 - Published 2 instances of "Hi to sharded channel1!" message on channel1 using sharded mode
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
async publish(message, channel, sharded = false) {
|
|
1023
|
+
return this.createWritePromise((0, Commands_1.createPublish)(message, channel, sharded));
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Lists the currently active shard channels.
|
|
1027
|
+
* The command is routed to all nodes, and aggregates the response to a single array.
|
|
1028
|
+
*
|
|
1029
|
+
* @see {@link https://valkey.io/commands/pubsub-shardchannels/|valkey.io} for details.
|
|
1030
|
+
*
|
|
1031
|
+
* @param options - (Optional) Additional parameters:
|
|
1032
|
+
* - (Optional) `pattern`: A glob-style pattern to match active shard channels.
|
|
1033
|
+
* If not provided, all active shard channels are returned.
|
|
1034
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
1035
|
+
* @returns A list of currently active shard channels matching the given pattern.
|
|
1036
|
+
* If no pattern is specified, all active shard channels are returned.
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```typescript
|
|
1040
|
+
* const allChannels = await client.pubsubShardchannels();
|
|
1041
|
+
* console.log(allChannels); // Output: ["channel1", "channel2"]
|
|
1042
|
+
*
|
|
1043
|
+
* const filteredChannels = await client.pubsubShardchannels("channel*");
|
|
1044
|
+
* console.log(filteredChannels); // Output: ["channel1", "channel2"]
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
async pubsubShardChannels(options) {
|
|
1048
|
+
return this.createWritePromise((0, Commands_1.createPubsubShardChannels)(options?.pattern), options);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified shard channels.
|
|
1052
|
+
*
|
|
1053
|
+
* @see {@link https://valkey.io/commands/pubsub-shardnumsub/|valkey.io} for details.
|
|
1054
|
+
* @remarks The command is routed to all nodes, and aggregates the response into a single list.
|
|
1055
|
+
*
|
|
1056
|
+
* @param channels - The list of shard channels to query for the number of subscribers.
|
|
1057
|
+
* @param options - (Optional) see {@link DecoderOption}.
|
|
1058
|
+
* @returns A list of the shard channel names and their numbers of subscribers.
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* const result1 = await client.pubsubShardnumsub(["channel1", "channel2"]);
|
|
1063
|
+
* console.log(result1); // Output:
|
|
1064
|
+
* // [{ channel: "channel1", numSub: 3}, { channel: "channel2", numSub: 5 }]
|
|
1065
|
+
*
|
|
1066
|
+
* const result2 = await client.pubsubShardnumsub([]);
|
|
1067
|
+
* console.log(result2); // Output: []
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
async pubsubShardNumSub(channels, options) {
|
|
1071
|
+
return this.createWritePromise((0, Commands_1.createPubSubShardNumSub)(channels), options).then((res) => res.map((r) => {
|
|
1072
|
+
return { channel: r.key, numSub: r.value };
|
|
1073
|
+
}));
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Returns `UNIX TIME` of the last DB save timestamp or startup timestamp if no save
|
|
1077
|
+
* was made since then.
|
|
1078
|
+
*
|
|
1079
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
1080
|
+
*
|
|
1081
|
+
* @see {@link https://valkey.io/commands/lastsave/|valkey.io} for details.
|
|
1082
|
+
*
|
|
1083
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
1084
|
+
* @returns `UNIX TIME` of the last DB save executed with success.
|
|
1085
|
+
*
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```typescript
|
|
1088
|
+
* const timestamp = await client.lastsave();
|
|
1089
|
+
* console.log("Last DB save was done at " + timestamp);
|
|
1090
|
+
* ```
|
|
1091
|
+
*/
|
|
1092
|
+
async lastsave(options) {
|
|
1093
|
+
return this.createWritePromise((0, Commands_1.createLastSave)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Returns a random existing key name.
|
|
1097
|
+
*
|
|
1098
|
+
* The command will be routed to all primary nodes, unless `route` is provided.
|
|
1099
|
+
*
|
|
1100
|
+
* @see {@link https://valkey.io/commands/randomkey/|valkey.io} for details.
|
|
1101
|
+
*
|
|
1102
|
+
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
|
|
1103
|
+
* @returns A random existing key name.
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```typescript
|
|
1107
|
+
* const result = await client.randomKey();
|
|
1108
|
+
* console.log(result); // Output: "key12" - "key12" is a random existing key name.
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
async randomKey(options) {
|
|
1112
|
+
return this.createWritePromise((0, Commands_1.createRandomKey)(), options);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Flushes all the previously watched keys for a transaction. Executing a transaction will
|
|
1116
|
+
* automatically flush all previously watched keys.
|
|
1117
|
+
*
|
|
1118
|
+
* The command will be routed to all primary nodes, unless `route` is provided
|
|
1119
|
+
*
|
|
1120
|
+
* @see {@link https://valkey.io/commands/unwatch/|valkey.io} and {@link https://valkey.io/topics/transactions/#cas|Valkey Glide Wiki} for more details.
|
|
1121
|
+
*
|
|
1122
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
1123
|
+
* @returns A simple `"OK"` response.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```typescript
|
|
1127
|
+
* let response = await client.watch(["sampleKey"]);
|
|
1128
|
+
* console.log(response); // Output: "OK"
|
|
1129
|
+
* response = await client.unwatch();
|
|
1130
|
+
* console.log(response); // Output: "OK"
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
async unwatch(options) {
|
|
1134
|
+
return this.createWritePromise((0, Commands_1.createUnWatch)(), {
|
|
1135
|
+
decoder: BaseClient_1.Decoder.String,
|
|
1136
|
+
...options,
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Invokes a Lua script with arguments.
|
|
1141
|
+
* This method simplifies the process of invoking scripts on a Valkey server by using an object that represents a Lua script.
|
|
1142
|
+
* The script loading, argument preparation, and execution will all be handled internally. If the script has not already been loaded,
|
|
1143
|
+
* it will be loaded automatically using the `SCRIPT LOAD` command. After that, it will be invoked using the `EVALSHA` command.
|
|
1144
|
+
*
|
|
1145
|
+
* The command will be routed to a random node, unless `route` is provided.
|
|
1146
|
+
*
|
|
1147
|
+
* @see {@link https://valkey.io/commands/script-load/|SCRIPT LOAD} and {@link https://valkey.io/commands/evalsha/|EVALSHA} on valkey.io for details.
|
|
1148
|
+
*
|
|
1149
|
+
* @param script - The Lua script to execute.
|
|
1150
|
+
* @param options - (Optional) Additional parameters:
|
|
1151
|
+
* - (Optional) `args`: the arguments for the script.
|
|
1152
|
+
* - (Optional) `decoder`: see {@link DecoderOption}.
|
|
1153
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
1154
|
+
* @returns A value that depends on the script that was executed.
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```typescript
|
|
1158
|
+
* const luaScript = new Script("return { ARGV[1] }");
|
|
1159
|
+
* const result = await client.invokeScript(luaScript, { args: ["bar"] });
|
|
1160
|
+
* console.log(result); // Output: ['bar']
|
|
1161
|
+
* ```
|
|
1162
|
+
*/
|
|
1163
|
+
async invokeScriptWithRoute(script, options) {
|
|
1164
|
+
const scriptInvocation = ProtobufMessage_1.command_request.ScriptInvocation.create({
|
|
1165
|
+
hash: script.getHash(),
|
|
1166
|
+
keys: [],
|
|
1167
|
+
args: options?.args?.map((arg) => typeof arg === "string" ? Buffer.from(arg) : arg),
|
|
1168
|
+
});
|
|
1169
|
+
return this.createScriptInvocationWithRoutePromise(scriptInvocation, options).then((res) => convertClusterGlideRecord(res, true, options?.route));
|
|
1170
|
+
}
|
|
1171
|
+
async createScriptInvocationWithRoutePromise(command, options) {
|
|
1172
|
+
this.ensureClientIsOpen();
|
|
1173
|
+
return new Promise((resolve, reject) => {
|
|
1174
|
+
const callbackIdx = this.getCallbackIndex();
|
|
1175
|
+
this.promiseCallbackFunctions[callbackIdx] = [
|
|
1176
|
+
resolve,
|
|
1177
|
+
reject,
|
|
1178
|
+
options?.decoder,
|
|
1179
|
+
];
|
|
1180
|
+
this.writeOrBufferRequest(new ProtobufMessage_1.command_request.CommandRequest({
|
|
1181
|
+
callbackIdx,
|
|
1182
|
+
scriptInvocation: command,
|
|
1183
|
+
route: this.toProtobufRoute(options?.route),
|
|
1184
|
+
}), (message, writer) => {
|
|
1185
|
+
ProtobufMessage_1.command_request.CommandRequest.encodeDelimited(message, writer);
|
|
1186
|
+
});
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Checks existence of scripts in the script cache by their SHA1 digest.
|
|
1191
|
+
*
|
|
1192
|
+
* @see {@link https://valkey.io/commands/script-exists/|valkey.io} for more details.
|
|
1193
|
+
*
|
|
1194
|
+
* @param sha1s - List of SHA1 digests of the scripts to check.
|
|
1195
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
1196
|
+
* @returns A list of boolean values indicating the existence of each script.
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```typescript
|
|
1200
|
+
* console result = await client.scriptExists(["sha1_digest1", "sha1_digest2"]);
|
|
1201
|
+
* console.log(result); // Output: [true, false]
|
|
1202
|
+
* ```
|
|
1203
|
+
*/
|
|
1204
|
+
async scriptExists(sha1s, options) {
|
|
1205
|
+
return this.createWritePromise((0, Commands_1.createScriptExists)(sha1s), options);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Flushes the Lua scripts cache.
|
|
1209
|
+
*
|
|
1210
|
+
* @see {@link https://valkey.io/commands/script-flush/|valkey.io} for more details.
|
|
1211
|
+
*
|
|
1212
|
+
* @param options - (Optional) Additional parameters:
|
|
1213
|
+
* - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
|
|
1214
|
+
* - (Optional) `route`: see {@link RouteOption}.
|
|
1215
|
+
* @returns A simple `"OK"` response.
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* ```typescript
|
|
1219
|
+
* console result = await client.scriptFlush(FlushMode.SYNC);
|
|
1220
|
+
* console.log(result); // Output: "OK"
|
|
1221
|
+
* ```
|
|
1222
|
+
*/
|
|
1223
|
+
async scriptFlush(options) {
|
|
1224
|
+
return this.createWritePromise((0, Commands_1.createScriptFlush)(options?.mode), {
|
|
1225
|
+
decoder: BaseClient_1.Decoder.String,
|
|
1226
|
+
...options,
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Kills the currently executing Lua script, assuming no write operation was yet performed by the script.
|
|
1231
|
+
*
|
|
1232
|
+
* @see {@link https://valkey.io/commands/script-kill/|valkey.io} for more details.
|
|
1233
|
+
* @remarks The command is routed to all nodes, and aggregates the response to a single array.
|
|
1234
|
+
*
|
|
1235
|
+
* @param options - (Optional) See {@link RouteOption}.
|
|
1236
|
+
* @returns A simple `"OK"` response.
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* console result = await client.scriptKill();
|
|
1241
|
+
* console.log(result); // Output: "OK"
|
|
1242
|
+
* ```
|
|
1243
|
+
*/
|
|
1244
|
+
async scriptKill(options) {
|
|
1245
|
+
return this.createWritePromise((0, Commands_1.createScriptKill)(), {
|
|
1246
|
+
decoder: BaseClient_1.Decoder.String,
|
|
1247
|
+
...options,
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
exports.GlideClusterClient = GlideClusterClient;
|