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