speedkey 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2951 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TimeUnit = exports.ScoreFilter = exports.SortOrder = exports.GeoUnit = exports.HashExpirationCondition = exports.HashFieldConditionalChange = exports.ConditionalChange = exports.FlushMode = exports.BitmapIndexType = exports.FunctionRestorePolicy = exports.InsertPosition = exports.InfBoundary = exports.UpdateByScore = exports.ExpireOptions = exports.ListDirection = exports.BitFieldOverflow = exports.BitOverflowControl = exports.BitFieldIncrBy = exports.BitFieldSet = exports.BitFieldGet = exports.BitOffsetMultiplier = exports.BitOffset = exports.UnsignedEncoding = exports.SignedEncoding = exports.BitwiseOperation = exports.InfoOptions = void 0;
10
+ exports.parseInfoResponse = parseInfoResponse;
11
+ exports.createGet = createGet;
12
+ exports.createGetDel = createGetDel;
13
+ exports.createGetRange = createGetRange;
14
+ exports.createSet = createSet;
15
+ exports.createPing = createPing;
16
+ exports.createInfo = createInfo;
17
+ exports.createDel = createDel;
18
+ exports.createSelect = createSelect;
19
+ exports.createClientGetName = createClientGetName;
20
+ exports.createConfigRewrite = createConfigRewrite;
21
+ exports.createConfigResetStat = createConfigResetStat;
22
+ exports.createMGet = createMGet;
23
+ exports.createMSet = createMSet;
24
+ exports.createMSetNX = createMSetNX;
25
+ exports.createIncr = createIncr;
26
+ exports.createIncrBy = createIncrBy;
27
+ exports.createIncrByFloat = createIncrByFloat;
28
+ exports.createClientId = createClientId;
29
+ exports.createConfigGet = createConfigGet;
30
+ exports.createConfigSet = createConfigSet;
31
+ exports.createHGet = createHGet;
32
+ exports.convertFieldsAndValuesToHashDataType = convertFieldsAndValuesToHashDataType;
33
+ exports.createHSet = createHSet;
34
+ exports.createHKeys = createHKeys;
35
+ exports.createHSetNX = createHSetNX;
36
+ exports.createHSetEx = createHSetEx;
37
+ exports.createHGetEx = createHGetEx;
38
+ exports.createHExpire = createHExpire;
39
+ exports.createHPersist = createHPersist;
40
+ exports.createHPExpire = createHPExpire;
41
+ exports.createHExpireAt = createHExpireAt;
42
+ exports.createHPExpireAt = createHPExpireAt;
43
+ exports.createHTtl = createHTtl;
44
+ exports.createHPTtl = createHPTtl;
45
+ exports.createHExpireTime = createHExpireTime;
46
+ exports.createHPExpireTime = createHPExpireTime;
47
+ exports.createDecr = createDecr;
48
+ exports.createDecrBy = createDecrBy;
49
+ exports.createBitOp = createBitOp;
50
+ exports.createGetBit = createGetBit;
51
+ exports.createSetBit = createSetBit;
52
+ exports.createBitField = createBitField;
53
+ exports.createHDel = createHDel;
54
+ exports.createHMGet = createHMGet;
55
+ exports.createHExists = createHExists;
56
+ exports.createHGetAll = createHGetAll;
57
+ exports.createLPush = createLPush;
58
+ exports.createLPushX = createLPushX;
59
+ exports.createLPop = createLPop;
60
+ exports.createLRange = createLRange;
61
+ exports.createLLen = createLLen;
62
+ exports.createLMove = createLMove;
63
+ exports.createBLMove = createBLMove;
64
+ exports.createLSet = createLSet;
65
+ exports.createLTrim = createLTrim;
66
+ exports.createLRem = createLRem;
67
+ exports.createRPush = createRPush;
68
+ exports.createRPushX = createRPushX;
69
+ exports.createRPop = createRPop;
70
+ exports.createSAdd = createSAdd;
71
+ exports.createSRem = createSRem;
72
+ exports.createSScan = createSScan;
73
+ exports.createSMembers = createSMembers;
74
+ exports.createSMove = createSMove;
75
+ exports.createSCard = createSCard;
76
+ exports.createSInter = createSInter;
77
+ exports.createSInterCard = createSInterCard;
78
+ exports.createSInterStore = createSInterStore;
79
+ exports.createSDiff = createSDiff;
80
+ exports.createSDiffStore = createSDiffStore;
81
+ exports.createSUnion = createSUnion;
82
+ exports.createSUnionStore = createSUnionStore;
83
+ exports.createSIsMember = createSIsMember;
84
+ exports.createSMIsMember = createSMIsMember;
85
+ exports.createSPop = createSPop;
86
+ exports.createSRandMember = createSRandMember;
87
+ exports.createCustomCommand = createCustomCommand;
88
+ exports.createHIncrBy = createHIncrBy;
89
+ exports.createHIncrByFloat = createHIncrByFloat;
90
+ exports.createHLen = createHLen;
91
+ exports.createHVals = createHVals;
92
+ exports.createExists = createExists;
93
+ exports.createUnlink = createUnlink;
94
+ exports.createExpire = createExpire;
95
+ exports.createExpireAt = createExpireAt;
96
+ exports.createExpireTime = createExpireTime;
97
+ exports.createPExpire = createPExpire;
98
+ exports.createPExpireAt = createPExpireAt;
99
+ exports.createPExpireTime = createPExpireTime;
100
+ exports.createTTL = createTTL;
101
+ exports.convertElementsAndScores = convertElementsAndScores;
102
+ exports.createZAdd = createZAdd;
103
+ exports.createZInterstore = createZInterstore;
104
+ exports.createZInter = createZInter;
105
+ exports.createZUnion = createZUnion;
106
+ exports.createZRem = createZRem;
107
+ exports.createZCard = createZCard;
108
+ exports.createZInterCard = createZInterCard;
109
+ exports.createZDiff = createZDiff;
110
+ exports.createZDiffWithScores = createZDiffWithScores;
111
+ exports.createZDiffStore = createZDiffStore;
112
+ exports.createZScore = createZScore;
113
+ exports.createZUnionStore = createZUnionStore;
114
+ exports.createZMScore = createZMScore;
115
+ exports.createScan = createScan;
116
+ exports.createZCount = createZCount;
117
+ exports.createZRange = createZRange;
118
+ exports.createZRangeWithScores = createZRangeWithScores;
119
+ exports.createZRangeStore = createZRangeStore;
120
+ exports.createType = createType;
121
+ exports.createStrlen = createStrlen;
122
+ exports.createLIndex = createLIndex;
123
+ exports.createLInsert = createLInsert;
124
+ exports.createZPopMin = createZPopMin;
125
+ exports.createZPopMax = createZPopMax;
126
+ exports.createEcho = createEcho;
127
+ exports.createPTTL = createPTTL;
128
+ exports.createZRemRangeByRank = createZRemRangeByRank;
129
+ exports.createZRemRangeByLex = createZRemRangeByLex;
130
+ exports.createZRemRangeByScore = createZRemRangeByScore;
131
+ exports.createPersist = createPersist;
132
+ exports.createZLexCount = createZLexCount;
133
+ exports.createZRank = createZRank;
134
+ exports.createXAdd = createXAdd;
135
+ exports.createXDel = createXDel;
136
+ exports.createXTrim = createXTrim;
137
+ exports.createXRange = createXRange;
138
+ exports.createXRevRange = createXRevRange;
139
+ exports.createXGroupCreateConsumer = createXGroupCreateConsumer;
140
+ exports.createXGroupDelConsumer = createXGroupDelConsumer;
141
+ exports.createTime = createTime;
142
+ exports.createPublish = createPublish;
143
+ exports.createBRPop = createBRPop;
144
+ exports.createBLPop = createBLPop;
145
+ exports.createFCall = createFCall;
146
+ exports.createFCallReadOnly = createFCallReadOnly;
147
+ exports.createFunctionDelete = createFunctionDelete;
148
+ exports.createFunctionFlush = createFunctionFlush;
149
+ exports.createFunctionLoad = createFunctionLoad;
150
+ exports.createFunctionList = createFunctionList;
151
+ exports.createFunctionStats = createFunctionStats;
152
+ exports.createFunctionKill = createFunctionKill;
153
+ exports.createFunctionDump = createFunctionDump;
154
+ exports.createFunctionRestore = createFunctionRestore;
155
+ exports.createBitCount = createBitCount;
156
+ exports.createBitPos = createBitPos;
157
+ exports.convertKeysAndEntries = convertKeysAndEntries;
158
+ exports.createXRead = createXRead;
159
+ exports.createXReadGroup = createXReadGroup;
160
+ exports.createXInfoStream = createXInfoStream;
161
+ exports.createXInfoGroups = createXInfoGroups;
162
+ exports.createXLen = createXLen;
163
+ exports.createXPending = createXPending;
164
+ exports.createXInfoConsumers = createXInfoConsumers;
165
+ exports.createXClaim = createXClaim;
166
+ exports.createXAutoClaim = createXAutoClaim;
167
+ exports.createXGroupCreate = createXGroupCreate;
168
+ exports.createXGroupDestroy = createXGroupDestroy;
169
+ exports.createRename = createRename;
170
+ exports.createRenameNX = createRenameNX;
171
+ exports.createPfAdd = createPfAdd;
172
+ exports.createPfCount = createPfCount;
173
+ exports.createPfMerge = createPfMerge;
174
+ exports.createObjectEncoding = createObjectEncoding;
175
+ exports.createObjectFreq = createObjectFreq;
176
+ exports.createObjectIdletime = createObjectIdletime;
177
+ exports.createObjectRefcount = createObjectRefcount;
178
+ exports.createLolwut = createLolwut;
179
+ exports.createFlushAll = createFlushAll;
180
+ exports.createFlushDB = createFlushDB;
181
+ exports.createCopy = createCopy;
182
+ exports.createMove = createMove;
183
+ exports.createDump = createDump;
184
+ exports.createRestore = createRestore;
185
+ exports.createLPos = createLPos;
186
+ exports.createDBSize = createDBSize;
187
+ exports.createGeoAdd = createGeoAdd;
188
+ exports.createGeoPos = createGeoPos;
189
+ exports.createGeoDist = createGeoDist;
190
+ exports.createGeoHash = createGeoHash;
191
+ exports.createGeoSearch = createGeoSearch;
192
+ exports.createGeoSearchStore = createGeoSearchStore;
193
+ exports.createZRevRank = createZRevRank;
194
+ exports.createZRevRankWithScore = createZRevRankWithScore;
195
+ exports.createZMPop = createZMPop;
196
+ exports.createBZMPop = createBZMPop;
197
+ exports.createZIncrBy = createZIncrBy;
198
+ exports.createSort = createSort;
199
+ exports.createSortReadOnly = createSortReadOnly;
200
+ exports.createHStrlen = createHStrlen;
201
+ exports.createHRandField = createHRandField;
202
+ exports.createHScan = createHScan;
203
+ exports.createZRandMember = createZRandMember;
204
+ exports.createLastSave = createLastSave;
205
+ exports.createLCS = createLCS;
206
+ exports.createTouch = createTouch;
207
+ exports.createRandomKey = createRandomKey;
208
+ exports.createWatch = createWatch;
209
+ exports.createUnWatch = createUnWatch;
210
+ exports.createWait = createWait;
211
+ exports.createZScan = createZScan;
212
+ exports.createSetRange = createSetRange;
213
+ exports.createAppend = createAppend;
214
+ exports.createLMPop = createLMPop;
215
+ exports.createBLMPop = createBLMPop;
216
+ exports.createPubSubChannels = createPubSubChannels;
217
+ exports.createPubSubNumPat = createPubSubNumPat;
218
+ exports.createPubSubNumSub = createPubSubNumSub;
219
+ exports.createPubsubShardChannels = createPubsubShardChannels;
220
+ exports.createPubSubShardNumSub = createPubSubShardNumSub;
221
+ exports.createBZPopMax = createBZPopMax;
222
+ exports.createBZPopMin = createBZPopMin;
223
+ exports.createScriptShow = createScriptShow;
224
+ exports.createGetEx = createGetEx;
225
+ exports.createXAck = createXAck;
226
+ exports.createXGroupSetid = createXGroupSetid;
227
+ exports.createScriptExists = createScriptExists;
228
+ exports.createScriptFlush = createScriptFlush;
229
+ exports.createScriptKill = createScriptKill;
230
+ /**
231
+ * Note: 'eslint-disable-line @typescript-eslint/no-unused-vars' is used intentionally
232
+ * to suppress unused import errors for types referenced only in JSDoc.
233
+ */
234
+ const long_1 = __importDefault(require("long"));
235
+ const BaseClient_1 = require("./BaseClient");
236
+ const native_1 = require("../build-ts/native");
237
+ const ProtobufMessage_1 = require("../build-ts/ProtobufMessage");
238
+ var RequestType = ProtobufMessage_1.command_request.RequestType;
239
+ function isLargeCommand(args) {
240
+ let lenSum = 0;
241
+ for (const arg of args) {
242
+ lenSum += arg.length;
243
+ if (lenSum >= native_1.MAX_REQUEST_ARGS_LEN) {
244
+ return true;
245
+ }
246
+ }
247
+ return false;
248
+ }
249
+ /**
250
+ * Convert a string array into Uint8Array[]
251
+ */
252
+ function toBuffersArray(args) {
253
+ const argsBytes = [];
254
+ for (const arg of args) {
255
+ if (Buffer.isBuffer(arg)) {
256
+ argsBytes.push(arg);
257
+ }
258
+ else if (typeof arg === "string") {
259
+ argsBytes.push(Buffer.from(arg));
260
+ }
261
+ else {
262
+ // Fallback for unexpected types (number, boolean, etc.)
263
+ argsBytes.push(Buffer.from(String(arg)));
264
+ }
265
+ }
266
+ return argsBytes;
267
+ }
268
+ /**
269
+ * @test
270
+ */
271
+ function parseInfoResponse(response) {
272
+ const lines = response.split("\n");
273
+ const parsedResponse = {};
274
+ for (const line of lines) {
275
+ // Ignore lines that start with '#'
276
+ if (!line.startsWith("#")) {
277
+ const [key, value] = line.trim().split(":");
278
+ parsedResponse[key] = value;
279
+ }
280
+ }
281
+ return parsedResponse;
282
+ }
283
+ function createCommand(requestType, args) {
284
+ const singleCommand = ProtobufMessage_1.command_request.Command.create({
285
+ requestType,
286
+ });
287
+ const argsBytes = toBuffersArray(args);
288
+ if (isLargeCommand(args)) {
289
+ // pass as a pointer
290
+ const pointerArr = (0, native_1.createLeakedStringVec)(argsBytes);
291
+ const pointer = new long_1.default(pointerArr[0], pointerArr[1]);
292
+ singleCommand.argsVecPointer = pointer;
293
+ }
294
+ else {
295
+ singleCommand.argsArray = ProtobufMessage_1.command_request.Command.ArgsArray.create({
296
+ args: argsBytes,
297
+ });
298
+ }
299
+ return singleCommand;
300
+ }
301
+ /**
302
+ * @internal
303
+ */
304
+ function createGet(key) {
305
+ return createCommand(RequestType.Get, [key]);
306
+ }
307
+ /**
308
+ * @internal
309
+ */
310
+ function createGetDel(key) {
311
+ return createCommand(RequestType.GetDel, [key]);
312
+ }
313
+ /**
314
+ * @internal
315
+ */
316
+ function createGetRange(key, start, end) {
317
+ return createCommand(RequestType.GetRange, [
318
+ key,
319
+ start.toString(),
320
+ end.toString(),
321
+ ]);
322
+ }
323
+ /**
324
+ * @internal
325
+ */
326
+ function createSet(key, value, options) {
327
+ const args = [key, value];
328
+ if (options) {
329
+ if (options.conditionalSet === "onlyIfExists") {
330
+ args.push("XX");
331
+ }
332
+ else if (options.conditionalSet === "onlyIfDoesNotExist") {
333
+ args.push("NX");
334
+ }
335
+ else if (options.conditionalSet === "onlyIfEqual") {
336
+ args.push("IFEQ", options.comparisonValue);
337
+ }
338
+ if (options.returnOldValue) {
339
+ args.push("GET");
340
+ }
341
+ if (options.expiry) {
342
+ if (options.expiry !== "keepExisting" &&
343
+ !Number.isInteger(options.expiry.count)) {
344
+ throw new Error(`Received expiry '${JSON.stringify(options.expiry)}'. Count must be an integer`);
345
+ }
346
+ if (options.expiry === "keepExisting") {
347
+ args.push("KEEPTTL");
348
+ }
349
+ else {
350
+ args.push(options.expiry.type, options.expiry.count.toString());
351
+ }
352
+ }
353
+ }
354
+ return createCommand(RequestType.Set, args);
355
+ }
356
+ /**
357
+ * INFO option: a specific section of information:
358
+ * When no parameter is provided, the default option is assumed.
359
+ */
360
+ var InfoOptions;
361
+ (function (InfoOptions) {
362
+ /**
363
+ * SERVER: General information about the server
364
+ */
365
+ InfoOptions["Server"] = "server";
366
+ /**
367
+ * CLIENTS: Client connections section
368
+ */
369
+ InfoOptions["Clients"] = "clients";
370
+ /**
371
+ * MEMORY: Memory consumption related information
372
+ */
373
+ InfoOptions["Memory"] = "memory";
374
+ /**
375
+ * PERSISTENCE: RDB and AOF related information
376
+ */
377
+ InfoOptions["Persistence"] = "persistence";
378
+ /**
379
+ * STATS: General statistics
380
+ */
381
+ InfoOptions["Stats"] = "stats";
382
+ /**
383
+ * REPLICATION: Master/replica replication information
384
+ */
385
+ InfoOptions["Replication"] = "replication";
386
+ /**
387
+ * CPU: CPU consumption statistics
388
+ */
389
+ InfoOptions["Cpu"] = "cpu";
390
+ /**
391
+ * COMMANDSTATS: Valkey command statistics
392
+ */
393
+ InfoOptions["Commandstats"] = "commandstats";
394
+ /**
395
+ * LATENCYSTATS: Valkey command latency percentile distribution statistics
396
+ */
397
+ InfoOptions["Latencystats"] = "latencystats";
398
+ /**
399
+ * SENTINEL: Valkey Sentinel section (only applicable to Sentinel instances)
400
+ */
401
+ InfoOptions["Sentinel"] = "sentinel";
402
+ /**
403
+ * CLUSTER: Valkey Cluster section
404
+ */
405
+ InfoOptions["Cluster"] = "cluster";
406
+ /**
407
+ * MODULES: Modules section
408
+ */
409
+ InfoOptions["Modules"] = "modules";
410
+ /**
411
+ * KEYSPACE: Database related statistics
412
+ */
413
+ InfoOptions["Keyspace"] = "keyspace";
414
+ /**
415
+ * ERRORSTATS: Valkey error statistics
416
+ */
417
+ InfoOptions["Errorstats"] = "errorstats";
418
+ /**
419
+ * ALL: Return all sections (excluding module generated ones)
420
+ */
421
+ InfoOptions["All"] = "all";
422
+ /**
423
+ * DEFAULT: Return only the default set of sections
424
+ */
425
+ InfoOptions["Default"] = "default";
426
+ /**
427
+ * EVERYTHING: Includes all and modules
428
+ */
429
+ InfoOptions["Everything"] = "everything";
430
+ })(InfoOptions || (exports.InfoOptions = InfoOptions = {}));
431
+ /**
432
+ * @internal
433
+ */
434
+ function createPing(str) {
435
+ const args = str == undefined ? [] : [str];
436
+ return createCommand(RequestType.Ping, args);
437
+ }
438
+ /**
439
+ * @internal
440
+ */
441
+ function createInfo(options) {
442
+ const args = options == undefined ? [] : options;
443
+ return createCommand(RequestType.Info, args);
444
+ }
445
+ /**
446
+ * @internal
447
+ */
448
+ function createDel(keys) {
449
+ return createCommand(RequestType.Del, keys);
450
+ }
451
+ /**
452
+ * @internal
453
+ */
454
+ function createSelect(index) {
455
+ return createCommand(RequestType.Select, [index.toString()]);
456
+ }
457
+ /**
458
+ * @internal
459
+ */
460
+ function createClientGetName() {
461
+ return createCommand(RequestType.ClientGetName, []);
462
+ }
463
+ /**
464
+ * @internal
465
+ */
466
+ function createConfigRewrite() {
467
+ return createCommand(RequestType.ConfigRewrite, []);
468
+ }
469
+ /**
470
+ * @internal
471
+ */
472
+ function createConfigResetStat() {
473
+ return createCommand(RequestType.ConfigResetStat, []);
474
+ }
475
+ /**
476
+ * @internal
477
+ */
478
+ function createMGet(keys) {
479
+ return createCommand(RequestType.MGet, keys);
480
+ }
481
+ /**
482
+ * @internal
483
+ */
484
+ function createMSet(keysAndValues) {
485
+ return createCommand(RequestType.MSet, keysAndValues.flatMap((e) => [e.key, e.value]));
486
+ }
487
+ /**
488
+ * @internal
489
+ */
490
+ function createMSetNX(keysAndValues) {
491
+ return createCommand(RequestType.MSetNX, keysAndValues.flatMap((e) => [e.key, e.value]));
492
+ }
493
+ /**
494
+ * @internal
495
+ */
496
+ function createIncr(key) {
497
+ return createCommand(RequestType.Incr, [key]);
498
+ }
499
+ /**
500
+ * @internal
501
+ */
502
+ function createIncrBy(key, amount) {
503
+ return createCommand(RequestType.IncrBy, [key, amount.toString()]);
504
+ }
505
+ /**
506
+ * @internal
507
+ */
508
+ function createIncrByFloat(key, amount) {
509
+ return createCommand(RequestType.IncrByFloat, [key, amount.toString()]);
510
+ }
511
+ /**
512
+ * @internal
513
+ */
514
+ function createClientId() {
515
+ return createCommand(RequestType.ClientId, []);
516
+ }
517
+ /**
518
+ * @internal
519
+ */
520
+ function createConfigGet(parameters) {
521
+ return createCommand(RequestType.ConfigGet, parameters);
522
+ }
523
+ /**
524
+ * @internal
525
+ */
526
+ function createConfigSet(parameters) {
527
+ return createCommand(RequestType.ConfigSet, Object.entries(parameters).flat());
528
+ }
529
+ /**
530
+ * @internal
531
+ */
532
+ function createHGet(key, field) {
533
+ return createCommand(RequestType.HGet, [key, field]);
534
+ }
535
+ /**
536
+ * This function converts an input from {@link HashDataType} or `Record` types to `HashDataType`.
537
+ *
538
+ * @param fieldsAndValues - field names and their values.
539
+ * @returns HashDataType array containing field names and their values.
540
+ */
541
+ function convertFieldsAndValuesToHashDataType(fieldsAndValues) {
542
+ if (!Array.isArray(fieldsAndValues)) {
543
+ return Object.entries(fieldsAndValues).map(([field, value]) => {
544
+ return { field, value };
545
+ });
546
+ }
547
+ return fieldsAndValues;
548
+ }
549
+ /**
550
+ * @internal
551
+ */
552
+ function createHSet(key, fieldValueList) {
553
+ return createCommand(RequestType.HSet, [key].concat(fieldValueList
554
+ .map((fieldValueObject) => [
555
+ fieldValueObject.field,
556
+ fieldValueObject.value,
557
+ ])
558
+ .flat()));
559
+ }
560
+ /**
561
+ * @internal
562
+ */
563
+ function createHKeys(key) {
564
+ return createCommand(RequestType.HKeys, [key]);
565
+ }
566
+ /**
567
+ * @internal
568
+ */
569
+ function createHSetNX(key, field, value) {
570
+ return createCommand(RequestType.HSetNX, [key, field, value]);
571
+ }
572
+ /**
573
+ * @internal
574
+ */
575
+ function createHSetEx(key, fieldValueMap, options) {
576
+ const args = [key];
577
+ // Add field conditional change options (FNX | FXX)
578
+ if (options?.fieldConditionalChange) {
579
+ args.push(options.fieldConditionalChange);
580
+ }
581
+ // Add expiry options (EX | PX | EXAT | PXAT | KEEPTTL)
582
+ // Note: PERSIST is not supported by HSETEX
583
+ if (options?.expiry) {
584
+ if (options.expiry === "KEEPTTL") {
585
+ args.push("KEEPTTL");
586
+ }
587
+ else {
588
+ // Validate that count is an integer
589
+ if (!Number.isInteger(options.expiry.count)) {
590
+ throw new Error(`HSETEX received expiry '${JSON.stringify(options.expiry)}'. Count must be an integer`);
591
+ }
592
+ args.push(options.expiry.type, options.expiry.count.toString());
593
+ }
594
+ }
595
+ // Only add FIELDS keyword and field count if fieldValueMap is not empty
596
+ if (fieldValueMap.length > 0) {
597
+ args.push("FIELDS", fieldValueMap.length.toString());
598
+ // Add field-value pairs
599
+ fieldValueMap.forEach((fieldValueObject) => {
600
+ args.push(fieldValueObject.field, fieldValueObject.value);
601
+ });
602
+ }
603
+ return createCommand(RequestType.HSetEx, args);
604
+ }
605
+ /**
606
+ * @internal
607
+ */
608
+ function createHGetEx(key, fields, options) {
609
+ const args = [key];
610
+ // Add expiry options (EX | PX | EXAT | PXAT | PERSIST)
611
+ // Note: HGETEX does not support KEEPTTL
612
+ if (options?.expiry) {
613
+ if (options.expiry === "PERSIST") {
614
+ args.push("PERSIST");
615
+ }
616
+ else {
617
+ // Validate that count is an integer
618
+ if (!Number.isInteger(options.expiry.count)) {
619
+ throw new Error(`HGETEX received expiry '${JSON.stringify(options.expiry)}'. Count must be an integer`);
620
+ }
621
+ args.push(options.expiry.type, options.expiry.count.toString());
622
+ }
623
+ }
624
+ // Add FIELDS keyword and field count - always required when fields parameter exists
625
+ args.push("FIELDS", fields.length.toString());
626
+ // Add field names
627
+ args.push(...fields);
628
+ return createCommand(RequestType.HGetEx, args);
629
+ }
630
+ /**
631
+ * @internal
632
+ */
633
+ function createHExpire(key, seconds, fields, options) {
634
+ const args = [key, seconds.toString()];
635
+ // Add condition options (NX | XX | GT | LT)
636
+ if (options?.condition) {
637
+ args.push(options.condition);
638
+ }
639
+ // Add FIELDS keyword and field count - always required when fields parameter exists
640
+ args.push("FIELDS", fields.length.toString());
641
+ // Add field names
642
+ args.push(...fields);
643
+ return createCommand(RequestType.HExpire, args);
644
+ }
645
+ /**
646
+ * @internal
647
+ */
648
+ function createHPersist(key, fields) {
649
+ const args = [key];
650
+ // Add FIELDS keyword and field count - always required when fields parameter exists
651
+ args.push("FIELDS", fields.length.toString());
652
+ // Add field names
653
+ args.push(...fields);
654
+ return createCommand(RequestType.HPersist, args);
655
+ }
656
+ /**
657
+ * @internal
658
+ */
659
+ function createHPExpire(key, milliseconds, fields, options) {
660
+ const args = [key, milliseconds.toString()];
661
+ // Add condition options (NX | XX | GT | LT)
662
+ if (options?.condition) {
663
+ args.push(options.condition);
664
+ }
665
+ // Add FIELDS keyword and field count - always required when fields parameter exists
666
+ args.push("FIELDS", fields.length.toString());
667
+ // Add field names
668
+ args.push(...fields);
669
+ return createCommand(RequestType.HPExpire, args);
670
+ }
671
+ /**
672
+ * @internal
673
+ */
674
+ function createHExpireAt(key, unixTimestampSeconds, fields, options) {
675
+ const args = [key, unixTimestampSeconds.toString()];
676
+ // Add condition options (NX | XX | GT | LT)
677
+ if (options?.condition) {
678
+ args.push(options.condition);
679
+ }
680
+ // Add FIELDS keyword and field count - always required when fields parameter exists
681
+ args.push("FIELDS", fields.length.toString());
682
+ // Add field names
683
+ args.push(...fields);
684
+ return createCommand(RequestType.HExpireAt, args);
685
+ }
686
+ /**
687
+ * @internal
688
+ */
689
+ function createHPExpireAt(key, unixTimestampMilliseconds, fields, options) {
690
+ const args = [key, unixTimestampMilliseconds.toString()];
691
+ // Add condition options (NX | XX | GT | LT)
692
+ if (options?.condition) {
693
+ args.push(options.condition);
694
+ }
695
+ // Add FIELDS keyword and field count - always required when fields parameter exists
696
+ args.push("FIELDS", fields.length.toString());
697
+ // Add field names
698
+ args.push(...fields);
699
+ return createCommand(RequestType.HPExpireAt, args);
700
+ }
701
+ /**
702
+ * @internal
703
+ */
704
+ function createHTtl(key, fields) {
705
+ const args = [key];
706
+ // Add FIELDS keyword and field count - always required when fields parameter exists
707
+ args.push("FIELDS", fields.length.toString());
708
+ // Add field names
709
+ args.push(...fields);
710
+ return createCommand(RequestType.HTtl, args);
711
+ }
712
+ /**
713
+ * @internal
714
+ */
715
+ function createHPTtl(key, fields) {
716
+ const args = [key];
717
+ // Add FIELDS keyword and field count - always required when fields parameter exists
718
+ args.push("FIELDS", fields.length.toString());
719
+ // Add field names
720
+ args.push(...fields);
721
+ return createCommand(RequestType.HPTtl, args);
722
+ }
723
+ /**
724
+ * @internal
725
+ */
726
+ function createHExpireTime(key, fields) {
727
+ const args = [key];
728
+ // Add FIELDS keyword and field count - always required when fields parameter exists
729
+ args.push("FIELDS", fields.length.toString());
730
+ // Add field names
731
+ args.push(...fields);
732
+ return createCommand(RequestType.HExpireTime, args);
733
+ }
734
+ /**
735
+ * @internal
736
+ */
737
+ function createHPExpireTime(key, fields) {
738
+ const args = [key];
739
+ // Add FIELDS keyword and field count - always required when fields parameter exists
740
+ args.push("FIELDS", fields.length.toString());
741
+ // Add field names
742
+ args.push(...fields);
743
+ return createCommand(RequestType.HPExpireTime, args);
744
+ }
745
+ /**
746
+ * @internal
747
+ */
748
+ function createDecr(key) {
749
+ return createCommand(RequestType.Decr, [key]);
750
+ }
751
+ /**
752
+ * @internal
753
+ */
754
+ function createDecrBy(key, amount) {
755
+ return createCommand(RequestType.DecrBy, [key, amount.toString()]);
756
+ }
757
+ /**
758
+ * Enumeration defining the bitwise operation to use in the {@link BaseClient.bitop|bitop} command. Specifies the
759
+ * bitwise operation to perform between the passed in keys.
760
+ */
761
+ var BitwiseOperation;
762
+ (function (BitwiseOperation) {
763
+ BitwiseOperation["AND"] = "AND";
764
+ BitwiseOperation["OR"] = "OR";
765
+ BitwiseOperation["XOR"] = "XOR";
766
+ BitwiseOperation["NOT"] = "NOT";
767
+ })(BitwiseOperation || (exports.BitwiseOperation = BitwiseOperation = {}));
768
+ /**
769
+ * @internal
770
+ */
771
+ function createBitOp(operation, destination, keys) {
772
+ return createCommand(RequestType.BitOp, [operation, destination, ...keys]);
773
+ }
774
+ /**
775
+ * @internal
776
+ */
777
+ function createGetBit(key, offset) {
778
+ return createCommand(RequestType.GetBit, [key, offset.toString()]);
779
+ }
780
+ /**
781
+ * @internal
782
+ */
783
+ function createSetBit(key, offset, value) {
784
+ return createCommand(RequestType.SetBit, [
785
+ key,
786
+ offset.toString(),
787
+ value.toString(),
788
+ ]);
789
+ }
790
+ /**
791
+ * Represents a signed argument encoding.
792
+ */
793
+ class SignedEncoding {
794
+ static SIGNED_ENCODING_PREFIX = "i";
795
+ encoding;
796
+ /**
797
+ * Creates an instance of SignedEncoding.
798
+ *
799
+ * @param encodingLength - The bit size of the encoding. Must be less than 65 bits long.
800
+ */
801
+ constructor(encodingLength) {
802
+ this.encoding = `${SignedEncoding.SIGNED_ENCODING_PREFIX}${encodingLength.toString()}`;
803
+ }
804
+ toArg() {
805
+ return this.encoding;
806
+ }
807
+ }
808
+ exports.SignedEncoding = SignedEncoding;
809
+ /**
810
+ * Represents an unsigned argument encoding.
811
+ */
812
+ class UnsignedEncoding {
813
+ static UNSIGNED_ENCODING_PREFIX = "u";
814
+ encoding;
815
+ /**
816
+ * Creates an instance of UnsignedEncoding.
817
+ *
818
+ * @param encodingLength - The bit size of the encoding. Must be less than 64 bits long.
819
+ */
820
+ constructor(encodingLength) {
821
+ this.encoding = `${UnsignedEncoding.UNSIGNED_ENCODING_PREFIX}${encodingLength.toString()}`;
822
+ }
823
+ toArg() {
824
+ return this.encoding;
825
+ }
826
+ }
827
+ exports.UnsignedEncoding = UnsignedEncoding;
828
+ /**
829
+ * Represents an offset in an array of bits for the {@link BaseClient.bitfield|bitfield} or
830
+ * {@link BaseClient.bitfieldReadOnly|bitfieldReadOnly} commands.
831
+ *
832
+ * For example, if we have the binary `01101001` with offset of 1 for an unsigned encoding of size 4, then the value
833
+ * is 13 from `0(1101)001`.
834
+ */
835
+ class BitOffset {
836
+ offset;
837
+ /**
838
+ * Creates an instance of BitOffset.
839
+ *
840
+ * @param offset - The bit index offset in the array of bits. Must be greater than or equal to 0.
841
+ */
842
+ constructor(offset) {
843
+ this.offset = offset.toString();
844
+ }
845
+ toArg() {
846
+ return this.offset;
847
+ }
848
+ }
849
+ exports.BitOffset = BitOffset;
850
+ /**
851
+ * Represents an offset in an array of bits for the {@link BaseClient.bitfield|bitfield} or
852
+ * {@link BaseClient.bitfieldReadOnly|bitfieldReadOnly} commands. The bit offset index is calculated as the numerical
853
+ * value of the offset multiplied by the encoding value.
854
+ *
855
+ * For example, if we have the binary 01101001 with offset multiplier of 1 for an unsigned encoding of size 4, then the
856
+ * value is 9 from `0110(1001)`.
857
+ */
858
+ class BitOffsetMultiplier {
859
+ static OFFSET_MULTIPLIER_PREFIX = "#";
860
+ offset;
861
+ /**
862
+ * Creates an instance of BitOffsetMultiplier.
863
+ *
864
+ * @param offset - The offset in the array of bits, which will be multiplied by the encoding value to get the final
865
+ * bit index offset.
866
+ */
867
+ constructor(offset) {
868
+ this.offset = `${BitOffsetMultiplier.OFFSET_MULTIPLIER_PREFIX}${offset.toString()}`;
869
+ }
870
+ toArg() {
871
+ return this.offset;
872
+ }
873
+ }
874
+ exports.BitOffsetMultiplier = BitOffsetMultiplier;
875
+ /**
876
+ * Represents the "GET" subcommand for getting a value in the binary representation of the string stored in `key`.
877
+ */
878
+ class BitFieldGet {
879
+ static GET_COMMAND_STRING = "GET";
880
+ encoding;
881
+ offset;
882
+ /**
883
+ * Creates an instance of BitFieldGet.
884
+ *
885
+ * @param encoding - The bit encoding for the subcommand.
886
+ * @param offset - The offset in the array of bits from which to get the value.
887
+ */
888
+ constructor(encoding, offset) {
889
+ this.encoding = encoding;
890
+ this.offset = offset;
891
+ }
892
+ toArgs() {
893
+ return [
894
+ BitFieldGet.GET_COMMAND_STRING,
895
+ this.encoding.toArg(),
896
+ this.offset.toArg(),
897
+ ];
898
+ }
899
+ }
900
+ exports.BitFieldGet = BitFieldGet;
901
+ /**
902
+ * Represents the "SET" subcommand for setting bits in the binary representation of the string stored in `key`.
903
+ */
904
+ class BitFieldSet {
905
+ static SET_COMMAND_STRING = "SET";
906
+ encoding;
907
+ offset;
908
+ value;
909
+ /**
910
+ * Creates an instance of BitFieldSet
911
+ *
912
+ * @param encoding - The bit encoding for the subcommand.
913
+ * @param offset - The offset in the array of bits where the value will be set.
914
+ * @param value - The value to set the bits in the binary value to.
915
+ */
916
+ constructor(encoding, offset, value) {
917
+ this.encoding = encoding;
918
+ this.offset = offset;
919
+ this.value = value;
920
+ }
921
+ toArgs() {
922
+ return [
923
+ BitFieldSet.SET_COMMAND_STRING,
924
+ this.encoding.toArg(),
925
+ this.offset.toArg(),
926
+ this.value.toString(),
927
+ ];
928
+ }
929
+ }
930
+ exports.BitFieldSet = BitFieldSet;
931
+ /**
932
+ * Represents the "INCRBY" subcommand for increasing or decreasing bits in the binary representation of the string
933
+ * stored in `key`.
934
+ */
935
+ class BitFieldIncrBy {
936
+ static INCRBY_COMMAND_STRING = "INCRBY";
937
+ encoding;
938
+ offset;
939
+ increment;
940
+ /**
941
+ * Creates an instance of BitFieldIncrBy
942
+ *
943
+ * @param encoding - The bit encoding for the subcommand.
944
+ * @param offset - The offset in the array of bits where the value will be incremented.
945
+ * @param increment - The value to increment the bits in the binary value by.
946
+ */
947
+ constructor(encoding, offset, increment) {
948
+ this.encoding = encoding;
949
+ this.offset = offset;
950
+ this.increment = increment;
951
+ }
952
+ toArgs() {
953
+ return [
954
+ BitFieldIncrBy.INCRBY_COMMAND_STRING,
955
+ this.encoding.toArg(),
956
+ this.offset.toArg(),
957
+ this.increment.toString(),
958
+ ];
959
+ }
960
+ }
961
+ exports.BitFieldIncrBy = BitFieldIncrBy;
962
+ /**
963
+ * Enumeration specifying bit overflow controls for the {@link BaseClient.bitfield|bitfield} command.
964
+ */
965
+ var BitOverflowControl;
966
+ (function (BitOverflowControl) {
967
+ /**
968
+ * Performs modulo when overflows occur with unsigned encoding. When overflows occur with signed encoding, the value
969
+ * restarts at the most negative value. When underflows occur with signed encoding, the value restarts at the most
970
+ * positive value.
971
+ */
972
+ BitOverflowControl["WRAP"] = "WRAP";
973
+ /**
974
+ * Underflows remain set to the minimum value, and overflows remain set to the maximum value.
975
+ */
976
+ BitOverflowControl["SAT"] = "SAT";
977
+ /**
978
+ * Returns `None` when overflows occur.
979
+ */
980
+ BitOverflowControl["FAIL"] = "FAIL";
981
+ })(BitOverflowControl || (exports.BitOverflowControl = BitOverflowControl = {}));
982
+ /**
983
+ * Represents the "OVERFLOW" subcommand that determines the result of the "SET" or "INCRBY"
984
+ * {@link BaseClient.bitfield|bitfield} subcommands when an underflow or overflow occurs.
985
+ */
986
+ class BitFieldOverflow {
987
+ static OVERFLOW_COMMAND_STRING = "OVERFLOW";
988
+ overflowControl;
989
+ /**
990
+ * Creates an instance of BitFieldOverflow.
991
+ *
992
+ * @param overflowControl - The desired overflow behavior.
993
+ */
994
+ constructor(overflowControl) {
995
+ this.overflowControl = overflowControl;
996
+ }
997
+ toArgs() {
998
+ return [BitFieldOverflow.OVERFLOW_COMMAND_STRING, this.overflowControl];
999
+ }
1000
+ }
1001
+ exports.BitFieldOverflow = BitFieldOverflow;
1002
+ /**
1003
+ * @internal
1004
+ */
1005
+ function createBitField(key, subcommands, readOnly = false) {
1006
+ const requestType = readOnly
1007
+ ? RequestType.BitFieldReadOnly
1008
+ : RequestType.BitField;
1009
+ let args = [key];
1010
+ for (const subcommand of subcommands) {
1011
+ args = args.concat(subcommand.toArgs());
1012
+ }
1013
+ return createCommand(requestType, args);
1014
+ }
1015
+ /**
1016
+ * @internal
1017
+ */
1018
+ function createHDel(key, fields) {
1019
+ return createCommand(RequestType.HDel, [key].concat(fields));
1020
+ }
1021
+ /**
1022
+ * @internal
1023
+ */
1024
+ function createHMGet(key, fields) {
1025
+ return createCommand(RequestType.HMGet, [key].concat(fields));
1026
+ }
1027
+ /**
1028
+ * @internal
1029
+ */
1030
+ function createHExists(key, field) {
1031
+ return createCommand(RequestType.HExists, [key, field]);
1032
+ }
1033
+ /**
1034
+ * @internal
1035
+ */
1036
+ function createHGetAll(key) {
1037
+ return createCommand(RequestType.HGetAll, [key]);
1038
+ }
1039
+ /**
1040
+ * @internal
1041
+ */
1042
+ function createLPush(key, elements) {
1043
+ return createCommand(RequestType.LPush, [key].concat(elements));
1044
+ }
1045
+ /**
1046
+ * @internal
1047
+ */
1048
+ function createLPushX(key, elements) {
1049
+ return createCommand(RequestType.LPushX, [key].concat(elements));
1050
+ }
1051
+ /**
1052
+ * @internal
1053
+ */
1054
+ function createLPop(key, count) {
1055
+ const args = count == undefined ? [key] : [key, count.toString()];
1056
+ return createCommand(RequestType.LPop, args);
1057
+ }
1058
+ /**
1059
+ * @internal
1060
+ */
1061
+ function createLRange(key, start, end) {
1062
+ return createCommand(RequestType.LRange, [
1063
+ key,
1064
+ start.toString(),
1065
+ end.toString(),
1066
+ ]);
1067
+ }
1068
+ /**
1069
+ * @internal
1070
+ */
1071
+ function createLLen(key) {
1072
+ return createCommand(RequestType.LLen, [key]);
1073
+ }
1074
+ /**
1075
+ * Enumeration representing element popping or adding direction for the List Based Commands.
1076
+ */
1077
+ var ListDirection;
1078
+ (function (ListDirection) {
1079
+ /**
1080
+ * Represents the option that elements should be popped from or added to the left side of a list.
1081
+ */
1082
+ ListDirection["LEFT"] = "LEFT";
1083
+ /**
1084
+ * Represents the option that elements should be popped from or added to the right side of a list.
1085
+ */
1086
+ ListDirection["RIGHT"] = "RIGHT";
1087
+ })(ListDirection || (exports.ListDirection = ListDirection = {}));
1088
+ /**
1089
+ * @internal
1090
+ */
1091
+ function createLMove(source, destination, whereFrom, whereTo) {
1092
+ return createCommand(RequestType.LMove, [
1093
+ source,
1094
+ destination,
1095
+ whereFrom,
1096
+ whereTo,
1097
+ ]);
1098
+ }
1099
+ /**
1100
+ * @internal
1101
+ */
1102
+ function createBLMove(source, destination, whereFrom, whereTo, timeout) {
1103
+ return createCommand(RequestType.BLMove, [
1104
+ source,
1105
+ destination,
1106
+ whereFrom,
1107
+ whereTo,
1108
+ timeout.toString(),
1109
+ ]);
1110
+ }
1111
+ /**
1112
+ * @internal
1113
+ */
1114
+ function createLSet(key, index, element) {
1115
+ return createCommand(RequestType.LSet, [key, index.toString(), element]);
1116
+ }
1117
+ /**
1118
+ * @internal
1119
+ */
1120
+ function createLTrim(key, start, end) {
1121
+ return createCommand(RequestType.LTrim, [
1122
+ key,
1123
+ start.toString(),
1124
+ end.toString(),
1125
+ ]);
1126
+ }
1127
+ /**
1128
+ * @internal
1129
+ */
1130
+ function createLRem(key, count, element) {
1131
+ return createCommand(RequestType.LRem, [key, count.toString(), element]);
1132
+ }
1133
+ /**
1134
+ * @internal
1135
+ */
1136
+ function createRPush(key, elements) {
1137
+ return createCommand(RequestType.RPush, [key].concat(elements));
1138
+ }
1139
+ /**
1140
+ * @internal
1141
+ */
1142
+ function createRPushX(key, elements) {
1143
+ return createCommand(RequestType.RPushX, [key].concat(elements));
1144
+ }
1145
+ /**
1146
+ * @internal
1147
+ */
1148
+ function createRPop(key, count) {
1149
+ const args = count == undefined ? [key] : [key, count.toString()];
1150
+ return createCommand(RequestType.RPop, args);
1151
+ }
1152
+ /**
1153
+ * @internal
1154
+ */
1155
+ function createSAdd(key, members) {
1156
+ return createCommand(RequestType.SAdd, [key].concat(members));
1157
+ }
1158
+ /**
1159
+ * @internal
1160
+ */
1161
+ function createSRem(key, members) {
1162
+ return createCommand(RequestType.SRem, [key].concat(members));
1163
+ }
1164
+ /**
1165
+ * @internal
1166
+ */
1167
+ function createSScan(key, cursor, options) {
1168
+ let args = [key, cursor];
1169
+ if (options) {
1170
+ args = args.concat(convertBaseScanOptionsToArgsArray(options));
1171
+ }
1172
+ return createCommand(RequestType.SScan, args);
1173
+ }
1174
+ /**
1175
+ * @internal
1176
+ */
1177
+ function createSMembers(key) {
1178
+ return createCommand(RequestType.SMembers, [key]);
1179
+ }
1180
+ /**
1181
+ *
1182
+ * @internal
1183
+ */
1184
+ function createSMove(source, destination, member) {
1185
+ return createCommand(RequestType.SMove, [source, destination, member]);
1186
+ }
1187
+ /**
1188
+ * @internal
1189
+ */
1190
+ function createSCard(key) {
1191
+ return createCommand(RequestType.SCard, [key]);
1192
+ }
1193
+ /**
1194
+ * @internal
1195
+ */
1196
+ function createSInter(keys) {
1197
+ return createCommand(RequestType.SInter, keys);
1198
+ }
1199
+ /**
1200
+ * @internal
1201
+ */
1202
+ function createSInterCard(keys, limit) {
1203
+ let args = keys;
1204
+ args.unshift(keys.length.toString());
1205
+ if (limit != undefined) {
1206
+ args = args.concat(["LIMIT", limit.toString()]);
1207
+ }
1208
+ return createCommand(RequestType.SInterCard, args);
1209
+ }
1210
+ /**
1211
+ * @internal
1212
+ */
1213
+ function createSInterStore(destination, keys) {
1214
+ return createCommand(RequestType.SInterStore, [destination].concat(keys));
1215
+ }
1216
+ /**
1217
+ * @internal
1218
+ */
1219
+ function createSDiff(keys) {
1220
+ return createCommand(RequestType.SDiff, keys);
1221
+ }
1222
+ /**
1223
+ * @internal
1224
+ */
1225
+ function createSDiffStore(destination, keys) {
1226
+ return createCommand(RequestType.SDiffStore, [destination].concat(keys));
1227
+ }
1228
+ /**
1229
+ * @internal
1230
+ */
1231
+ function createSUnion(keys) {
1232
+ return createCommand(RequestType.SUnion, keys);
1233
+ }
1234
+ /**
1235
+ * @internal
1236
+ */
1237
+ function createSUnionStore(destination, keys) {
1238
+ return createCommand(RequestType.SUnionStore, [destination].concat(keys));
1239
+ }
1240
+ /**
1241
+ * @internal
1242
+ */
1243
+ function createSIsMember(key, member) {
1244
+ return createCommand(RequestType.SIsMember, [key, member]);
1245
+ }
1246
+ /**
1247
+ * @internal
1248
+ */
1249
+ function createSMIsMember(key, members) {
1250
+ return createCommand(RequestType.SMIsMember, [key].concat(members));
1251
+ }
1252
+ /**
1253
+ * @internal
1254
+ */
1255
+ function createSPop(key, count) {
1256
+ const args = count == undefined ? [key] : [key, count.toString()];
1257
+ return createCommand(RequestType.SPop, args);
1258
+ }
1259
+ /**
1260
+ * @internal
1261
+ */
1262
+ function createSRandMember(key, count) {
1263
+ const args = count == undefined ? [key] : [key, count.toString()];
1264
+ return createCommand(RequestType.SRandMember, args);
1265
+ }
1266
+ /**
1267
+ * @internal
1268
+ */
1269
+ function createCustomCommand(args) {
1270
+ return createCommand(RequestType.CustomCommand, args);
1271
+ }
1272
+ /**
1273
+ * @internal
1274
+ */
1275
+ function createHIncrBy(key, field, amount) {
1276
+ return createCommand(RequestType.HIncrBy, [key, field, amount.toString()]);
1277
+ }
1278
+ /**
1279
+ * @internal
1280
+ */
1281
+ function createHIncrByFloat(key, field, amount) {
1282
+ return createCommand(RequestType.HIncrByFloat, [
1283
+ key,
1284
+ field,
1285
+ amount.toString(),
1286
+ ]);
1287
+ }
1288
+ /**
1289
+ * @internal
1290
+ */
1291
+ function createHLen(key) {
1292
+ return createCommand(RequestType.HLen, [key]);
1293
+ }
1294
+ /**
1295
+ * @internal
1296
+ */
1297
+ function createHVals(key) {
1298
+ return createCommand(RequestType.HVals, [key]);
1299
+ }
1300
+ /**
1301
+ * @internal
1302
+ */
1303
+ function createExists(keys) {
1304
+ return createCommand(RequestType.Exists, keys);
1305
+ }
1306
+ /**
1307
+ * @internal
1308
+ */
1309
+ function createUnlink(keys) {
1310
+ return createCommand(RequestType.Unlink, keys);
1311
+ }
1312
+ var ExpireOptions;
1313
+ (function (ExpireOptions) {
1314
+ /**
1315
+ * `HasNoExpiry` - Sets expiry only when the key has no expiry.
1316
+ */
1317
+ ExpireOptions["HasNoExpiry"] = "NX";
1318
+ /**
1319
+ * `HasExistingExpiry` - Sets expiry only when the key has an existing expiry.
1320
+ */
1321
+ ExpireOptions["HasExistingExpiry"] = "XX";
1322
+ /**
1323
+ * `NewExpiryGreaterThanCurrent` - Sets expiry only when the new expiry is
1324
+ * greater than current one.
1325
+ */
1326
+ ExpireOptions["NewExpiryGreaterThanCurrent"] = "GT";
1327
+ /**
1328
+ * `NewExpiryLessThanCurrent` - Sets expiry only when the new expiry is less
1329
+ * than current one.
1330
+ */
1331
+ ExpireOptions["NewExpiryLessThanCurrent"] = "LT";
1332
+ })(ExpireOptions || (exports.ExpireOptions = ExpireOptions = {}));
1333
+ /**
1334
+ * @internal
1335
+ */
1336
+ function createExpire(key, seconds, option) {
1337
+ const args = option == undefined
1338
+ ? [key, seconds.toString()]
1339
+ : [key, seconds.toString(), option];
1340
+ return createCommand(RequestType.Expire, args);
1341
+ }
1342
+ /**
1343
+ * @internal
1344
+ */
1345
+ function createExpireAt(key, unixSeconds, option) {
1346
+ const args = option == undefined
1347
+ ? [key, unixSeconds.toString()]
1348
+ : [key, unixSeconds.toString(), option];
1349
+ return createCommand(RequestType.ExpireAt, args);
1350
+ }
1351
+ /**
1352
+ * @internal
1353
+ */
1354
+ function createExpireTime(key) {
1355
+ return createCommand(RequestType.ExpireTime, [key]);
1356
+ }
1357
+ /**
1358
+ * @internal
1359
+ */
1360
+ function createPExpire(key, milliseconds, option) {
1361
+ const args = option == undefined
1362
+ ? [key, milliseconds.toString()]
1363
+ : [key, milliseconds.toString(), option];
1364
+ return createCommand(RequestType.PExpire, args);
1365
+ }
1366
+ /**
1367
+ * @internal
1368
+ */
1369
+ function createPExpireAt(key, unixMilliseconds, option) {
1370
+ const args = option == undefined
1371
+ ? [key, unixMilliseconds.toString()]
1372
+ : [key, unixMilliseconds.toString(), option];
1373
+ return createCommand(RequestType.PExpireAt, args);
1374
+ }
1375
+ /**
1376
+ * @internal
1377
+ */
1378
+ function createPExpireTime(key) {
1379
+ return createCommand(RequestType.PExpireTime, [key]);
1380
+ }
1381
+ /**
1382
+ * @internal
1383
+ */
1384
+ function createTTL(key) {
1385
+ return createCommand(RequestType.TTL, [key]);
1386
+ }
1387
+ /**
1388
+ * Options for updating elements of a sorted set key.
1389
+ */
1390
+ var UpdateByScore;
1391
+ (function (UpdateByScore) {
1392
+ /** Only update existing elements if the new score is less than the current score. */
1393
+ UpdateByScore["LESS_THAN"] = "LT";
1394
+ /** Only update existing elements if the new score is greater than the current score. */
1395
+ UpdateByScore["GREATER_THAN"] = "GT";
1396
+ })(UpdateByScore || (exports.UpdateByScore = UpdateByScore = {}));
1397
+ /**
1398
+ * @internal
1399
+ * Convert input from `Record` to `SortedSetDataType` to ensure the only one type.
1400
+ */
1401
+ function convertElementsAndScores(membersAndScores) {
1402
+ if (!Array.isArray(membersAndScores)) {
1403
+ // convert Record<string, number> to SortedSetDataType
1404
+ return Object.entries(membersAndScores).map((element) => {
1405
+ return { element: element[0], score: element[1] };
1406
+ });
1407
+ }
1408
+ return membersAndScores;
1409
+ }
1410
+ /**
1411
+ * @internal
1412
+ */
1413
+ function createZAdd(key, membersAndScores, options, incr = false) {
1414
+ const args = [key];
1415
+ if (options) {
1416
+ if (options.conditionalChange) {
1417
+ if (options.conditionalChange ===
1418
+ ConditionalChange.ONLY_IF_DOES_NOT_EXIST &&
1419
+ options.updateOptions) {
1420
+ throw new Error(`The GT, LT, and NX options are mutually exclusive. Cannot choose both ${options.updateOptions} and NX.`);
1421
+ }
1422
+ args.push(options.conditionalChange);
1423
+ }
1424
+ if (options.updateOptions) {
1425
+ args.push(options.updateOptions);
1426
+ }
1427
+ if (options.changed) {
1428
+ args.push("CH");
1429
+ }
1430
+ }
1431
+ if (incr) {
1432
+ args.push("INCR");
1433
+ }
1434
+ if (Array.isArray(membersAndScores)) {
1435
+ for (let i = 0, len = membersAndScores.length; i < len; i++) {
1436
+ const item = membersAndScores[i];
1437
+ args.push(item.score.toString(), item.element);
1438
+ }
1439
+ }
1440
+ else {
1441
+ const members = Object.keys(membersAndScores);
1442
+ for (let i = 0, len = members.length; i < len; i++) {
1443
+ const member = members[i];
1444
+ args.push(membersAndScores[member].toString(), member);
1445
+ }
1446
+ }
1447
+ return createCommand(RequestType.ZAdd, args);
1448
+ }
1449
+ /**
1450
+ * @internal
1451
+ */
1452
+ function createZInterstore(destination, keys, aggregationType) {
1453
+ const args = createZCmdArgs(keys, {
1454
+ aggregationType,
1455
+ withScores: false,
1456
+ destination,
1457
+ });
1458
+ return createCommand(RequestType.ZInterStore, args);
1459
+ }
1460
+ /**
1461
+ * @internal
1462
+ */
1463
+ function createZInter(keys, aggregationType, withScores) {
1464
+ const args = createZCmdArgs(keys, { aggregationType, withScores });
1465
+ return createCommand(RequestType.ZInter, args);
1466
+ }
1467
+ /**
1468
+ * @internal
1469
+ */
1470
+ function createZUnion(keys, aggregationType, withScores) {
1471
+ const args = createZCmdArgs(keys, { aggregationType, withScores });
1472
+ return createCommand(RequestType.ZUnion, args);
1473
+ }
1474
+ /**
1475
+ * @internal
1476
+ * Helper function for Zcommands (ZInter, ZinterStore, ZUnion..) that arranges arguments in the server's required order.
1477
+ */
1478
+ function createZCmdArgs(keys, options) {
1479
+ const args = [];
1480
+ const destination = options.destination;
1481
+ if (destination) {
1482
+ args.push(destination);
1483
+ }
1484
+ args.push(keys.length.toString());
1485
+ if (!Array.isArray(keys[0])) {
1486
+ // KeyWeight is an array
1487
+ args.push(...keys);
1488
+ }
1489
+ else {
1490
+ const weightsKeys = keys.map(([key]) => key);
1491
+ args.push(...weightsKeys);
1492
+ const weights = keys.map(([, weight]) => weight.toString());
1493
+ args.push("WEIGHTS", ...weights);
1494
+ }
1495
+ const aggregationType = options.aggregationType;
1496
+ if (aggregationType) {
1497
+ args.push("AGGREGATE", aggregationType);
1498
+ }
1499
+ if (options.withScores) {
1500
+ args.push("WITHSCORES");
1501
+ }
1502
+ return args;
1503
+ }
1504
+ /**
1505
+ * @internal
1506
+ */
1507
+ function createZRem(key, members) {
1508
+ return createCommand(RequestType.ZRem, [key].concat(members));
1509
+ }
1510
+ /**
1511
+ * @internal
1512
+ */
1513
+ function createZCard(key) {
1514
+ return createCommand(RequestType.ZCard, [key]);
1515
+ }
1516
+ /**
1517
+ * @internal
1518
+ */
1519
+ function createZInterCard(keys, limit) {
1520
+ const args = keys;
1521
+ args.unshift(keys.length.toString());
1522
+ if (limit != undefined) {
1523
+ args.push("LIMIT", limit.toString());
1524
+ }
1525
+ return createCommand(RequestType.ZInterCard, args);
1526
+ }
1527
+ /**
1528
+ * @internal
1529
+ */
1530
+ function createZDiff(keys) {
1531
+ const args = keys;
1532
+ args.unshift(keys.length.toString());
1533
+ return createCommand(RequestType.ZDiff, args);
1534
+ }
1535
+ /**
1536
+ * @internal
1537
+ */
1538
+ function createZDiffWithScores(keys) {
1539
+ const args = keys;
1540
+ args.unshift(keys.length.toString());
1541
+ args.push("WITHSCORES");
1542
+ return createCommand(RequestType.ZDiff, args);
1543
+ }
1544
+ /**
1545
+ * @internal
1546
+ */
1547
+ function createZDiffStore(destination, keys) {
1548
+ const args = [destination, keys.length.toString(), ...keys];
1549
+ return createCommand(RequestType.ZDiffStore, args);
1550
+ }
1551
+ /**
1552
+ * @internal
1553
+ */
1554
+ function createZScore(key, member) {
1555
+ return createCommand(RequestType.ZScore, [key, member]);
1556
+ }
1557
+ /**
1558
+ * @internal
1559
+ */
1560
+ function createZUnionStore(destination, keys, aggregationType) {
1561
+ const args = createZCmdArgs(keys, { destination, aggregationType });
1562
+ return createCommand(RequestType.ZUnionStore, args);
1563
+ }
1564
+ /**
1565
+ * @internal
1566
+ */
1567
+ function createZMScore(key, members) {
1568
+ return createCommand(RequestType.ZMScore, [key, ...members]);
1569
+ }
1570
+ /**
1571
+ * @internal
1572
+ */
1573
+ function createScan(cursor, options) {
1574
+ let args = [cursor];
1575
+ if (options) {
1576
+ args = args.concat(convertBaseScanOptionsToArgsArray(options));
1577
+ }
1578
+ if (options?.type) {
1579
+ args.push("TYPE", options.type);
1580
+ }
1581
+ return createCommand(RequestType.Scan, args);
1582
+ }
1583
+ var InfBoundary;
1584
+ (function (InfBoundary) {
1585
+ /**
1586
+ * Positive infinity bound.
1587
+ */
1588
+ InfBoundary["PositiveInfinity"] = "+";
1589
+ /**
1590
+ * Negative infinity bound.
1591
+ */
1592
+ InfBoundary["NegativeInfinity"] = "-";
1593
+ })(InfBoundary || (exports.InfBoundary = InfBoundary = {}));
1594
+ /** Returns a string representation of a score boundary as a command argument. */
1595
+ function getScoreBoundaryArg(score) {
1596
+ if (typeof score === "string") {
1597
+ // InfBoundary
1598
+ return score + "inf";
1599
+ }
1600
+ if (score.isInclusive == false) {
1601
+ return "(" + score.value.toString();
1602
+ }
1603
+ return score.value.toString();
1604
+ }
1605
+ /** Returns a string representation of a lex boundary as a command argument. */
1606
+ function getLexBoundaryArg(score) {
1607
+ if (typeof score === "string") {
1608
+ // InfBoundary
1609
+ return score;
1610
+ }
1611
+ if (score.isInclusive == false) {
1612
+ return typeof score.value === "string"
1613
+ ? "(" + score.value
1614
+ : Buffer.concat([Buffer.from("("), score.value]);
1615
+ }
1616
+ return typeof score.value === "string"
1617
+ ? "[" + score.value
1618
+ : Buffer.concat([Buffer.from("["), score.value]);
1619
+ }
1620
+ /** Returns a string representation of a stream boundary as a command argument. */
1621
+ function getStreamBoundaryArg(boundary) {
1622
+ if (typeof boundary === "string") {
1623
+ // InfBoundary
1624
+ return boundary;
1625
+ }
1626
+ if (boundary.isInclusive == false) {
1627
+ return "(" + boundary.value.toString();
1628
+ }
1629
+ return boundary.value.toString();
1630
+ }
1631
+ function createZRangeArgs(key, rangeQuery, reverse, withScores) {
1632
+ const args = [key];
1633
+ if (typeof rangeQuery.start != "number") {
1634
+ rangeQuery = rangeQuery;
1635
+ if (rangeQuery.type == "byLex") {
1636
+ args.push(getLexBoundaryArg(rangeQuery.start), getLexBoundaryArg(rangeQuery.end), "BYLEX");
1637
+ }
1638
+ else {
1639
+ args.push(getScoreBoundaryArg(rangeQuery.start), getScoreBoundaryArg(rangeQuery.end), "BYSCORE");
1640
+ }
1641
+ }
1642
+ else {
1643
+ args.push(rangeQuery.start.toString());
1644
+ args.push(rangeQuery.end.toString());
1645
+ }
1646
+ if (reverse) {
1647
+ args.push("REV");
1648
+ }
1649
+ if ("limit" in rangeQuery && rangeQuery.limit !== undefined) {
1650
+ args.push("LIMIT", String(rangeQuery.limit.offset), String(rangeQuery.limit.count));
1651
+ }
1652
+ if (withScores) {
1653
+ args.push("WITHSCORES");
1654
+ }
1655
+ return args;
1656
+ }
1657
+ /**
1658
+ * @internal
1659
+ */
1660
+ function createZCount(key, minScore, maxScore) {
1661
+ const args = [
1662
+ key,
1663
+ getScoreBoundaryArg(minScore),
1664
+ getScoreBoundaryArg(maxScore),
1665
+ ];
1666
+ return createCommand(RequestType.ZCount, args);
1667
+ }
1668
+ /**
1669
+ * @internal
1670
+ */
1671
+ function createZRange(key, rangeQuery, reverse = false) {
1672
+ const args = createZRangeArgs(key, rangeQuery, reverse, false);
1673
+ return createCommand(RequestType.ZRange, args);
1674
+ }
1675
+ /**
1676
+ * @internal
1677
+ */
1678
+ function createZRangeWithScores(key, rangeQuery, reverse = false) {
1679
+ const args = createZRangeArgs(key, rangeQuery, reverse, true);
1680
+ return createCommand(RequestType.ZRange, args);
1681
+ }
1682
+ /**
1683
+ * @internal
1684
+ */
1685
+ function createZRangeStore(destination, source, rangeQuery, reverse = false) {
1686
+ const args = [
1687
+ destination,
1688
+ ...createZRangeArgs(source, rangeQuery, reverse, false),
1689
+ ];
1690
+ return createCommand(RequestType.ZRangeStore, args);
1691
+ }
1692
+ /**
1693
+ * @internal
1694
+ */
1695
+ function createType(key) {
1696
+ return createCommand(RequestType.Type, [key]);
1697
+ }
1698
+ /**
1699
+ * @internal
1700
+ */
1701
+ function createStrlen(key) {
1702
+ return createCommand(RequestType.Strlen, [key]);
1703
+ }
1704
+ /**
1705
+ * @internal
1706
+ */
1707
+ function createLIndex(key, index) {
1708
+ return createCommand(RequestType.LIndex, [key, index.toString()]);
1709
+ }
1710
+ /**
1711
+ * Defines where to insert new elements into a list.
1712
+ */
1713
+ var InsertPosition;
1714
+ (function (InsertPosition) {
1715
+ /**
1716
+ * Insert new element before the pivot.
1717
+ */
1718
+ InsertPosition["Before"] = "before";
1719
+ /**
1720
+ * Insert new element after the pivot.
1721
+ */
1722
+ InsertPosition["After"] = "after";
1723
+ })(InsertPosition || (exports.InsertPosition = InsertPosition = {}));
1724
+ /**
1725
+ * @internal
1726
+ */
1727
+ function createLInsert(key, position, pivot, element) {
1728
+ return createCommand(RequestType.LInsert, [key, position, pivot, element]);
1729
+ }
1730
+ /**
1731
+ * @internal
1732
+ */
1733
+ function createZPopMin(key, count) {
1734
+ const args = count == undefined ? [key] : [key, count.toString()];
1735
+ return createCommand(RequestType.ZPopMin, args);
1736
+ }
1737
+ /**
1738
+ * @internal
1739
+ */
1740
+ function createZPopMax(key, count) {
1741
+ const args = count == undefined ? [key] : [key, count.toString()];
1742
+ return createCommand(RequestType.ZPopMax, args);
1743
+ }
1744
+ /**
1745
+ * @internal
1746
+ */
1747
+ function createEcho(message) {
1748
+ return createCommand(RequestType.Echo, [message]);
1749
+ }
1750
+ /**
1751
+ * @internal
1752
+ */
1753
+ function createPTTL(key) {
1754
+ return createCommand(RequestType.PTTL, [key]);
1755
+ }
1756
+ /**
1757
+ * @internal
1758
+ */
1759
+ function createZRemRangeByRank(key, start, end) {
1760
+ return createCommand(RequestType.ZRemRangeByRank, [
1761
+ key,
1762
+ start.toString(),
1763
+ end.toString(),
1764
+ ]);
1765
+ }
1766
+ /**
1767
+ * @internal
1768
+ */
1769
+ function createZRemRangeByLex(key, minLex, maxLex) {
1770
+ const args = [key, getLexBoundaryArg(minLex), getLexBoundaryArg(maxLex)];
1771
+ return createCommand(RequestType.ZRemRangeByLex, args);
1772
+ }
1773
+ /**
1774
+ * @internal
1775
+ */
1776
+ function createZRemRangeByScore(key, minScore, maxScore) {
1777
+ const args = [
1778
+ key,
1779
+ getScoreBoundaryArg(minScore),
1780
+ getScoreBoundaryArg(maxScore),
1781
+ ];
1782
+ return createCommand(RequestType.ZRemRangeByScore, args);
1783
+ }
1784
+ /** @internal */
1785
+ function createPersist(key) {
1786
+ return createCommand(RequestType.Persist, [key]);
1787
+ }
1788
+ /**
1789
+ * @internal
1790
+ */
1791
+ function createZLexCount(key, minLex, maxLex) {
1792
+ const args = [key, getLexBoundaryArg(minLex), getLexBoundaryArg(maxLex)];
1793
+ return createCommand(RequestType.ZLexCount, args);
1794
+ }
1795
+ /** @internal */
1796
+ function createZRank(key, member, withScores) {
1797
+ const args = [key, member];
1798
+ if (withScores) {
1799
+ args.push("WITHSCORE");
1800
+ }
1801
+ return createCommand(RequestType.ZRank, args);
1802
+ }
1803
+ function addTrimOptions(options, args) {
1804
+ if (options.method === "maxlen") {
1805
+ args.push("MAXLEN");
1806
+ }
1807
+ else if (options.method === "minid") {
1808
+ args.push("MINID");
1809
+ }
1810
+ if (options.exact) {
1811
+ args.push("=");
1812
+ }
1813
+ else {
1814
+ args.push("~");
1815
+ }
1816
+ if (options.method === "maxlen") {
1817
+ args.push(options.threshold.toString());
1818
+ }
1819
+ else if (options.method === "minid") {
1820
+ args.push(options.threshold);
1821
+ }
1822
+ if (options.limit) {
1823
+ args.push("LIMIT");
1824
+ args.push(options.limit.toString());
1825
+ }
1826
+ }
1827
+ /**
1828
+ * @internal
1829
+ */
1830
+ function createXAdd(key, values, options) {
1831
+ const args = [key];
1832
+ if (options?.makeStream === false) {
1833
+ args.push("NOMKSTREAM");
1834
+ }
1835
+ if (options?.trim) {
1836
+ addTrimOptions(options.trim, args);
1837
+ }
1838
+ if (options?.id) {
1839
+ args.push(options.id);
1840
+ }
1841
+ else {
1842
+ args.push("*");
1843
+ }
1844
+ values.forEach(([field, value]) => {
1845
+ args.push(field);
1846
+ args.push(value);
1847
+ });
1848
+ return createCommand(RequestType.XAdd, args);
1849
+ }
1850
+ /**
1851
+ * @internal
1852
+ */
1853
+ function createXDel(key, ids) {
1854
+ return createCommand(RequestType.XDel, [key, ...ids]);
1855
+ }
1856
+ /**
1857
+ * @internal
1858
+ */
1859
+ function createXTrim(key, options) {
1860
+ const args = [key];
1861
+ addTrimOptions(options, args);
1862
+ return createCommand(RequestType.XTrim, args);
1863
+ }
1864
+ /**
1865
+ * @internal
1866
+ */
1867
+ function createXRange(key, start, end, count) {
1868
+ const args = [key, getStreamBoundaryArg(start), getStreamBoundaryArg(end)];
1869
+ if (count !== undefined) {
1870
+ args.push("COUNT");
1871
+ args.push(count.toString());
1872
+ }
1873
+ return createCommand(RequestType.XRange, args);
1874
+ }
1875
+ /**
1876
+ * @internal
1877
+ */
1878
+ function createXRevRange(key, start, end, count) {
1879
+ const args = [key, getStreamBoundaryArg(start), getStreamBoundaryArg(end)];
1880
+ if (count !== undefined) {
1881
+ args.push("COUNT");
1882
+ args.push(count.toString());
1883
+ }
1884
+ return createCommand(RequestType.XRevRange, args);
1885
+ }
1886
+ /**
1887
+ * @internal
1888
+ */
1889
+ function createXGroupCreateConsumer(key, groupName, consumerName) {
1890
+ return createCommand(RequestType.XGroupCreateConsumer, [
1891
+ key,
1892
+ groupName,
1893
+ consumerName,
1894
+ ]);
1895
+ }
1896
+ /**
1897
+ * @internal
1898
+ */
1899
+ function createXGroupDelConsumer(key, groupName, consumerName) {
1900
+ return createCommand(RequestType.XGroupDelConsumer, [
1901
+ key,
1902
+ groupName,
1903
+ consumerName,
1904
+ ]);
1905
+ }
1906
+ /**
1907
+ * @internal
1908
+ */
1909
+ function createTime() {
1910
+ return createCommand(RequestType.Time, []);
1911
+ }
1912
+ /**
1913
+ * @internal
1914
+ */
1915
+ function createPublish(message, channel, sharded = false) {
1916
+ const request = sharded ? RequestType.SPublish : RequestType.Publish;
1917
+ return createCommand(request, [channel, message]);
1918
+ }
1919
+ /**
1920
+ * @internal
1921
+ */
1922
+ function createBRPop(keys, timeout) {
1923
+ const args = [...keys, timeout.toString()];
1924
+ return createCommand(RequestType.BRPop, args);
1925
+ }
1926
+ /**
1927
+ * @internal
1928
+ */
1929
+ function createBLPop(keys, timeout) {
1930
+ const args = [...keys, timeout.toString()];
1931
+ return createCommand(RequestType.BLPop, args);
1932
+ }
1933
+ /**
1934
+ * @internal
1935
+ */
1936
+ function createFCall(func, keys, args) {
1937
+ const params = [
1938
+ func,
1939
+ keys.length.toString(),
1940
+ ...keys,
1941
+ ...args,
1942
+ ];
1943
+ return createCommand(RequestType.FCall, params);
1944
+ }
1945
+ /**
1946
+ * @internal
1947
+ */
1948
+ function createFCallReadOnly(func, keys, args) {
1949
+ const params = [
1950
+ func,
1951
+ keys.length.toString(),
1952
+ ...keys,
1953
+ ...args,
1954
+ ];
1955
+ return createCommand(RequestType.FCallReadOnly, params);
1956
+ }
1957
+ /**
1958
+ * @internal
1959
+ */
1960
+ function createFunctionDelete(libraryCode) {
1961
+ return createCommand(RequestType.FunctionDelete, [libraryCode]);
1962
+ }
1963
+ /**
1964
+ * @internal
1965
+ */
1966
+ function createFunctionFlush(mode) {
1967
+ if (mode) {
1968
+ return createCommand(RequestType.FunctionFlush, [mode.toString()]);
1969
+ }
1970
+ else {
1971
+ return createCommand(RequestType.FunctionFlush, []);
1972
+ }
1973
+ }
1974
+ /**
1975
+ * @internal
1976
+ */
1977
+ function createFunctionLoad(libraryCode, replace) {
1978
+ const args = replace ? ["REPLACE", libraryCode] : [libraryCode];
1979
+ return createCommand(RequestType.FunctionLoad, args);
1980
+ }
1981
+ /**
1982
+ * @internal
1983
+ */
1984
+ function createFunctionList(options) {
1985
+ const args = [];
1986
+ if (options) {
1987
+ if (options.libNamePattern) {
1988
+ args.push("LIBRARYNAME", options.libNamePattern);
1989
+ }
1990
+ if (options.withCode) {
1991
+ args.push("WITHCODE");
1992
+ }
1993
+ }
1994
+ return createCommand(RequestType.FunctionList, args);
1995
+ }
1996
+ /** @internal */
1997
+ function createFunctionStats() {
1998
+ return createCommand(RequestType.FunctionStats, []);
1999
+ }
2000
+ /** @internal */
2001
+ function createFunctionKill() {
2002
+ return createCommand(RequestType.FunctionKill, []);
2003
+ }
2004
+ /** @internal */
2005
+ function createFunctionDump() {
2006
+ return createCommand(RequestType.FunctionDump, []);
2007
+ }
2008
+ /**
2009
+ * Option for `FUNCTION RESTORE` command: {@link GlideClient.functionRestore} and
2010
+ * {@link GlideClusterClient.functionRestore}.
2011
+ *
2012
+ * @see {@link https://valkey.io/commands/function-restore/"|valkey.io} for more details.
2013
+ */
2014
+ var FunctionRestorePolicy;
2015
+ (function (FunctionRestorePolicy) {
2016
+ /**
2017
+ * Appends the restored libraries to the existing libraries and aborts on collision. This is the
2018
+ * default policy.
2019
+ */
2020
+ FunctionRestorePolicy["APPEND"] = "APPEND";
2021
+ /** Deletes all existing libraries before restoring the payload. */
2022
+ FunctionRestorePolicy["FLUSH"] = "FLUSH";
2023
+ /**
2024
+ * Appends the restored libraries to the existing libraries, replacing any existing ones in case
2025
+ * of name collisions. Note that this policy doesn't prevent function name collisions, only
2026
+ * libraries.
2027
+ */
2028
+ FunctionRestorePolicy["REPLACE"] = "REPLACE";
2029
+ })(FunctionRestorePolicy || (exports.FunctionRestorePolicy = FunctionRestorePolicy = {}));
2030
+ /** @internal */
2031
+ function createFunctionRestore(data, policy) {
2032
+ return createCommand(RequestType.FunctionRestore, policy ? [data, policy] : [data]);
2033
+ }
2034
+ /**
2035
+ * @internal
2036
+ */
2037
+ function convertBitOptionsToArgs(options) {
2038
+ const args = [];
2039
+ if (!options)
2040
+ return args;
2041
+ args.push(options.start.toString());
2042
+ if (options.end !== undefined) {
2043
+ args.push(options.end.toString());
2044
+ if (options.indexType)
2045
+ args.push(options.indexType);
2046
+ }
2047
+ return args;
2048
+ }
2049
+ /**
2050
+ * @internal
2051
+ */
2052
+ function createBitCount(key, options) {
2053
+ let args = [key];
2054
+ if (options) {
2055
+ const optionResults = convertBitOptionsToArgs(options);
2056
+ args = args.concat(optionResults);
2057
+ }
2058
+ return createCommand(RequestType.BitCount, args);
2059
+ }
2060
+ /**
2061
+ * Enumeration specifying if index arguments are BYTE indexes or BIT indexes.
2062
+ * Can be specified in {@link BitOffsetOptions}, which is an optional argument to the {@link BaseClient.bitcount|bitcount} command.
2063
+ * Can also be specified as an optional argument to the {@link BaseClient.bitposInverval|bitposInterval} command.
2064
+ *
2065
+ * since - Valkey version 7.0.0.
2066
+ */
2067
+ var BitmapIndexType;
2068
+ (function (BitmapIndexType) {
2069
+ /** Specifies that provided indexes are byte indexes. */
2070
+ BitmapIndexType["BYTE"] = "BYTE";
2071
+ /** Specifies that provided indexes are bit indexes. */
2072
+ BitmapIndexType["BIT"] = "BIT";
2073
+ })(BitmapIndexType || (exports.BitmapIndexType = BitmapIndexType = {}));
2074
+ /**
2075
+ * @internal
2076
+ */
2077
+ function createBitPos(key, bit, options) {
2078
+ const args = [
2079
+ key,
2080
+ bit.toString(),
2081
+ ...convertBitOptionsToArgs(options),
2082
+ ];
2083
+ return createCommand(RequestType.BitPos, args);
2084
+ }
2085
+ /**
2086
+ * Defines flushing mode for {@link GlideClient.flushall}, {@link GlideClusterClient.flushall},
2087
+ * {@link GlideClient.functionFlush}, {@link GlideClusterClient.functionFlush},
2088
+ * {@link GlideClient.flushdb} and {@link GlideClusterClient.flushdb} commands.
2089
+ *
2090
+ * See https://valkey.io/commands/flushall/ and https://valkey.io/commands/flushdb/ for details.
2091
+ */
2092
+ var FlushMode;
2093
+ (function (FlushMode) {
2094
+ /**
2095
+ * Flushes synchronously.
2096
+ *
2097
+ * since Valkey version 6.2.0.
2098
+ */
2099
+ FlushMode["SYNC"] = "SYNC";
2100
+ /** Flushes asynchronously. */
2101
+ FlushMode["ASYNC"] = "ASYNC";
2102
+ })(FlushMode || (exports.FlushMode = FlushMode = {}));
2103
+ /**
2104
+ * @internal
2105
+ * This function converts an input from Record or GlideRecord types to GlideRecord.
2106
+ *
2107
+ * @param record - input record in either Record or GlideRecord types.
2108
+ * @returns same data in GlideRecord type.
2109
+ */
2110
+ function convertKeysAndEntries(record) {
2111
+ if (!Array.isArray(record)) {
2112
+ return (0, BaseClient_1.convertRecordToGlideRecord)(record);
2113
+ }
2114
+ return record;
2115
+ }
2116
+ /** @internal */
2117
+ function addReadOptions(options) {
2118
+ const args = [];
2119
+ if (options?.count !== undefined) {
2120
+ args.push("COUNT");
2121
+ args.push(options.count.toString());
2122
+ }
2123
+ if (options?.block !== undefined) {
2124
+ args.push("BLOCK");
2125
+ args.push(options.block.toString());
2126
+ }
2127
+ return args;
2128
+ }
2129
+ /** @internal */
2130
+ function addStreamsArgs(keys_and_ids) {
2131
+ return [
2132
+ "STREAMS",
2133
+ ...keys_and_ids.map((e) => e.key),
2134
+ ...keys_and_ids.map((e) => e.value),
2135
+ ];
2136
+ }
2137
+ /**
2138
+ * @internal
2139
+ */
2140
+ function createXRead(keys_and_ids, options) {
2141
+ const args = addReadOptions(options);
2142
+ args.push(...addStreamsArgs(keys_and_ids));
2143
+ return createCommand(RequestType.XRead, args);
2144
+ }
2145
+ /** @internal */
2146
+ function createXReadGroup(group, consumer, keys_and_ids, options) {
2147
+ const args = ["GROUP", group, consumer];
2148
+ if (options) {
2149
+ args.push(...addReadOptions(options));
2150
+ if (options.noAck)
2151
+ args.push("NOACK");
2152
+ }
2153
+ args.push(...addStreamsArgs(keys_and_ids));
2154
+ return createCommand(RequestType.XReadGroup, args);
2155
+ }
2156
+ /**
2157
+ * @internal
2158
+ */
2159
+ function createXInfoStream(key, options) {
2160
+ const args = [key];
2161
+ if (options != false) {
2162
+ args.push("FULL");
2163
+ if (typeof options === "number") {
2164
+ args.push("COUNT");
2165
+ args.push(options.toString());
2166
+ }
2167
+ }
2168
+ return createCommand(RequestType.XInfoStream, args);
2169
+ }
2170
+ /** @internal */
2171
+ function createXInfoGroups(key) {
2172
+ return createCommand(RequestType.XInfoGroups, [key]);
2173
+ }
2174
+ /**
2175
+ * @internal
2176
+ */
2177
+ function createXLen(key) {
2178
+ return createCommand(RequestType.XLen, [key]);
2179
+ }
2180
+ /** @internal */
2181
+ function createXPending(key, group, options) {
2182
+ const args = [key, group];
2183
+ if (options) {
2184
+ if (options.minIdleTime !== undefined)
2185
+ args.push("IDLE", options.minIdleTime.toString());
2186
+ args.push(getStreamBoundaryArg(options.start), getStreamBoundaryArg(options.end), options.count.toString());
2187
+ if (options.consumer)
2188
+ args.push(options.consumer);
2189
+ }
2190
+ return createCommand(RequestType.XPending, args);
2191
+ }
2192
+ /** @internal */
2193
+ function createXInfoConsumers(key, group) {
2194
+ return createCommand(RequestType.XInfoConsumers, [key, group]);
2195
+ }
2196
+ /** @internal */
2197
+ function createXClaim(key, group, consumer, minIdleTime, ids, options, justId) {
2198
+ const args = [key, group, consumer, minIdleTime.toString(), ...ids];
2199
+ if (options) {
2200
+ if (options.idle !== undefined)
2201
+ args.push("IDLE", options.idle.toString());
2202
+ if (options.idleUnixTime !== undefined)
2203
+ args.push("TIME", options.idleUnixTime.toString());
2204
+ if (options.retryCount !== undefined)
2205
+ args.push("RETRYCOUNT", options.retryCount.toString());
2206
+ if (options.isForce)
2207
+ args.push("FORCE");
2208
+ }
2209
+ if (justId)
2210
+ args.push("JUSTID");
2211
+ return createCommand(RequestType.XClaim, args);
2212
+ }
2213
+ /** @internal */
2214
+ function createXAutoClaim(key, group, consumer, minIdleTime, start, count, justId) {
2215
+ const args = [
2216
+ key,
2217
+ group,
2218
+ consumer,
2219
+ minIdleTime.toString(),
2220
+ start.toString(),
2221
+ ];
2222
+ if (count !== undefined)
2223
+ args.push("COUNT", count.toString());
2224
+ if (justId)
2225
+ args.push("JUSTID");
2226
+ return createCommand(RequestType.XAutoClaim, args);
2227
+ }
2228
+ /**
2229
+ * @internal
2230
+ */
2231
+ function createXGroupCreate(key, groupName, id, options) {
2232
+ const args = [key, groupName, id];
2233
+ if (options) {
2234
+ if (options.mkStream) {
2235
+ args.push("MKSTREAM");
2236
+ }
2237
+ if (options.entriesRead) {
2238
+ args.push("ENTRIESREAD");
2239
+ args.push(options.entriesRead);
2240
+ }
2241
+ }
2242
+ return createCommand(RequestType.XGroupCreate, args);
2243
+ }
2244
+ /**
2245
+ * @internal
2246
+ */
2247
+ function createXGroupDestroy(key, groupName) {
2248
+ return createCommand(RequestType.XGroupDestroy, [key, groupName]);
2249
+ }
2250
+ /**
2251
+ * @internal
2252
+ */
2253
+ function createRename(key, newKey) {
2254
+ return createCommand(RequestType.Rename, [key, newKey]);
2255
+ }
2256
+ /**
2257
+ * @internal
2258
+ */
2259
+ function createRenameNX(key, newKey) {
2260
+ return createCommand(RequestType.RenameNX, [key, newKey]);
2261
+ }
2262
+ /**
2263
+ * @internal
2264
+ */
2265
+ function createPfAdd(key, elements) {
2266
+ const args = [key, ...elements];
2267
+ return createCommand(RequestType.PfAdd, args);
2268
+ }
2269
+ /**
2270
+ * @internal
2271
+ */
2272
+ function createPfCount(keys) {
2273
+ return createCommand(RequestType.PfCount, keys);
2274
+ }
2275
+ /**
2276
+ * @internal
2277
+ */
2278
+ function createPfMerge(destination, sourceKey) {
2279
+ return createCommand(RequestType.PfMerge, [destination, ...sourceKey]);
2280
+ }
2281
+ /**
2282
+ * @internal
2283
+ */
2284
+ function createObjectEncoding(key) {
2285
+ return createCommand(RequestType.ObjectEncoding, [key]);
2286
+ }
2287
+ /**
2288
+ * @internal
2289
+ */
2290
+ function createObjectFreq(key) {
2291
+ return createCommand(RequestType.ObjectFreq, [key]);
2292
+ }
2293
+ /**
2294
+ * @internal
2295
+ */
2296
+ function createObjectIdletime(key) {
2297
+ return createCommand(RequestType.ObjectIdleTime, [key]);
2298
+ }
2299
+ /**
2300
+ * @internal
2301
+ */
2302
+ function createObjectRefcount(key) {
2303
+ return createCommand(RequestType.ObjectRefCount, [key]);
2304
+ }
2305
+ /**
2306
+ * @internal
2307
+ */
2308
+ function createLolwut(options) {
2309
+ const args = [];
2310
+ if (options) {
2311
+ if (options.version !== undefined) {
2312
+ args.push("VERSION", options.version.toString());
2313
+ }
2314
+ if (options.parameters !== undefined) {
2315
+ args.push(...options.parameters.map((param) => param.toString()));
2316
+ }
2317
+ }
2318
+ return createCommand(RequestType.Lolwut, args);
2319
+ }
2320
+ /**
2321
+ * @internal
2322
+ */
2323
+ function createFlushAll(mode) {
2324
+ if (mode) {
2325
+ return createCommand(RequestType.FlushAll, [mode.toString()]);
2326
+ }
2327
+ else {
2328
+ return createCommand(RequestType.FlushAll, []);
2329
+ }
2330
+ }
2331
+ /**
2332
+ * @internal
2333
+ */
2334
+ function createFlushDB(mode) {
2335
+ if (mode) {
2336
+ return createCommand(RequestType.FlushDB, [mode.toString()]);
2337
+ }
2338
+ else {
2339
+ return createCommand(RequestType.FlushDB, []);
2340
+ }
2341
+ }
2342
+ /**
2343
+ * @internal
2344
+ */
2345
+ function createCopy(source, destination, options) {
2346
+ let args = [source, destination];
2347
+ if (options) {
2348
+ if (options.destinationDB !== undefined) {
2349
+ args = args.concat("DB", options.destinationDB.toString());
2350
+ }
2351
+ if (options.replace) {
2352
+ args.push("REPLACE");
2353
+ }
2354
+ }
2355
+ return createCommand(RequestType.Copy, args);
2356
+ }
2357
+ /**
2358
+ * @internal
2359
+ */
2360
+ function createMove(key, dbIndex) {
2361
+ return createCommand(RequestType.Move, [key, dbIndex.toString()]);
2362
+ }
2363
+ /**
2364
+ * @internal
2365
+ */
2366
+ function createDump(key) {
2367
+ return createCommand(RequestType.Dump, [key]);
2368
+ }
2369
+ /**
2370
+ * @internal
2371
+ */
2372
+ function createRestore(key, ttl, value, options) {
2373
+ const args = [key, ttl.toString(), value];
2374
+ if (options) {
2375
+ if (options.idletime !== undefined && options.frequency !== undefined) {
2376
+ throw new Error(`syntax error: both IDLETIME and FREQ cannot be set at the same time.`);
2377
+ }
2378
+ if (options.replace) {
2379
+ args.push("REPLACE");
2380
+ }
2381
+ if (options.absttl) {
2382
+ args.push("ABSTTL");
2383
+ }
2384
+ if (options.idletime !== undefined) {
2385
+ args.push("IDLETIME", options.idletime.toString());
2386
+ }
2387
+ if (options.frequency !== undefined) {
2388
+ args.push("FREQ", options.frequency.toString());
2389
+ }
2390
+ }
2391
+ return createCommand(RequestType.Restore, args);
2392
+ }
2393
+ /**
2394
+ * @internal
2395
+ */
2396
+ function createLPos(key, element, options) {
2397
+ const args = [key, element];
2398
+ if (options) {
2399
+ if (options.rank !== undefined) {
2400
+ args.push("RANK");
2401
+ args.push(options.rank.toString());
2402
+ }
2403
+ if (options.count !== undefined) {
2404
+ args.push("COUNT");
2405
+ args.push(options.count.toString());
2406
+ }
2407
+ if (options.maxLength !== undefined) {
2408
+ args.push("MAXLEN");
2409
+ args.push(options.maxLength.toString());
2410
+ }
2411
+ }
2412
+ return createCommand(RequestType.LPos, args);
2413
+ }
2414
+ /**
2415
+ * @internal
2416
+ */
2417
+ function createDBSize() {
2418
+ return createCommand(RequestType.DBSize, []);
2419
+ }
2420
+ /**
2421
+ * An optional condition to the {@link BaseClient.geoadd | geoadd},
2422
+ * {@link BaseClient.zadd | zadd} and {@link BaseClient.set | set} commands.
2423
+ */
2424
+ var ConditionalChange;
2425
+ (function (ConditionalChange) {
2426
+ /**
2427
+ * Only update elements that already exist. Don't add new elements. Equivalent to `XX` in the Valkey API.
2428
+ */
2429
+ ConditionalChange["ONLY_IF_EXISTS"] = "XX";
2430
+ /**
2431
+ * Only add new elements. Don't update already existing elements. Equivalent to `NX` in the Valkey API.
2432
+ */
2433
+ ConditionalChange["ONLY_IF_DOES_NOT_EXIST"] = "NX";
2434
+ })(ConditionalChange || (exports.ConditionalChange = ConditionalChange = {}));
2435
+ /**
2436
+ * Field conditional change options for hash field expiration commands.
2437
+ * Used with HSETEX command to control field setting behavior.
2438
+ */
2439
+ var HashFieldConditionalChange;
2440
+ (function (HashFieldConditionalChange) {
2441
+ /**
2442
+ * Only set fields if all of them already exist. Equivalent to `FXX` in the Valkey API.
2443
+ */
2444
+ HashFieldConditionalChange["ONLY_IF_ALL_EXIST"] = "FXX";
2445
+ /**
2446
+ * Only set fields if none of them already exist. Equivalent to `FNX` in the Valkey API.
2447
+ */
2448
+ HashFieldConditionalChange["ONLY_IF_NONE_EXIST"] = "FNX";
2449
+ })(HashFieldConditionalChange || (exports.HashFieldConditionalChange = HashFieldConditionalChange = {}));
2450
+ /**
2451
+ * Expiration condition options for hash field expiration commands.
2452
+ * Used with HEXPIRE, HPEXPIRE, HEXPIREAT, and HPEXPIREAT commands to control expiration setting behavior.
2453
+ */
2454
+ var HashExpirationCondition;
2455
+ (function (HashExpirationCondition) {
2456
+ /**
2457
+ * Only set expiration when field has no expiration. Equivalent to `NX` in the Valkey API.
2458
+ */
2459
+ HashExpirationCondition["ONLY_IF_NO_EXPIRY"] = "NX";
2460
+ /**
2461
+ * Only set expiration when field has existing expiration. Equivalent to `XX` in the Valkey API.
2462
+ */
2463
+ HashExpirationCondition["ONLY_IF_HAS_EXPIRY"] = "XX";
2464
+ /**
2465
+ * Only set expiration when new expiration is greater than current. Equivalent to `GT` in the Valkey API.
2466
+ */
2467
+ HashExpirationCondition["ONLY_IF_GREATER_THAN_CURRENT"] = "GT";
2468
+ /**
2469
+ * Only set expiration when new expiration is less than current. Equivalent to `LT` in the Valkey API.
2470
+ */
2471
+ HashExpirationCondition["ONLY_IF_LESS_THAN_CURRENT"] = "LT";
2472
+ })(HashExpirationCondition || (exports.HashExpirationCondition = HashExpirationCondition = {}));
2473
+ /**
2474
+ * @internal
2475
+ */
2476
+ function createGeoAdd(key, membersToGeospatialData, options) {
2477
+ let args = [key];
2478
+ if (options) {
2479
+ if (options.updateMode) {
2480
+ args.push(options.updateMode);
2481
+ }
2482
+ if (options.changed) {
2483
+ args.push("CH");
2484
+ }
2485
+ }
2486
+ membersToGeospatialData.forEach((coord, member) => {
2487
+ args = args.concat(coord.longitude.toString(), coord.latitude.toString(), member);
2488
+ });
2489
+ return createCommand(RequestType.GeoAdd, args);
2490
+ }
2491
+ /** Enumeration representing distance units options. */
2492
+ var GeoUnit;
2493
+ (function (GeoUnit) {
2494
+ /** Represents distance in meters. */
2495
+ GeoUnit["METERS"] = "m";
2496
+ /** Represents distance in kilometers. */
2497
+ GeoUnit["KILOMETERS"] = "km";
2498
+ /** Represents distance in miles. */
2499
+ GeoUnit["MILES"] = "mi";
2500
+ /** Represents distance in feet. */
2501
+ GeoUnit["FEET"] = "ft";
2502
+ })(GeoUnit || (exports.GeoUnit = GeoUnit = {}));
2503
+ /**
2504
+ * @internal
2505
+ */
2506
+ function createGeoPos(key, members) {
2507
+ return createCommand(RequestType.GeoPos, [key].concat(members));
2508
+ }
2509
+ /**
2510
+ * @internal
2511
+ */
2512
+ function createGeoDist(key, member1, member2, geoUnit) {
2513
+ const args = [key, member1, member2];
2514
+ if (geoUnit) {
2515
+ args.push(geoUnit);
2516
+ }
2517
+ return createCommand(RequestType.GeoDist, args);
2518
+ }
2519
+ /**
2520
+ * @internal
2521
+ */
2522
+ function createGeoHash(key, members) {
2523
+ const args = [key].concat(members);
2524
+ return createCommand(RequestType.GeoHash, args);
2525
+ }
2526
+ /** Defines the sort order for nested results. */
2527
+ var SortOrder;
2528
+ (function (SortOrder) {
2529
+ /** Sort by ascending order. */
2530
+ SortOrder["ASC"] = "ASC";
2531
+ /** Sort by descending order. */
2532
+ SortOrder["DESC"] = "DESC";
2533
+ })(SortOrder || (exports.SortOrder = SortOrder = {}));
2534
+ /** @internal */
2535
+ function createGeoSearch(key, searchFrom, searchBy, resultOptions) {
2536
+ const args = [key].concat(convertGeoSearchOptionsToArgs(searchFrom, searchBy, resultOptions));
2537
+ return createCommand(RequestType.GeoSearch, args);
2538
+ }
2539
+ /** @internal */
2540
+ function createGeoSearchStore(destination, source, searchFrom, searchBy, resultOptions) {
2541
+ const args = [destination, source].concat(convertGeoSearchOptionsToArgs(searchFrom, searchBy, resultOptions));
2542
+ return createCommand(RequestType.GeoSearchStore, args);
2543
+ }
2544
+ function convertGeoSearchOptionsToArgs(searchFrom, searchBy, resultOptions) {
2545
+ let args = [];
2546
+ if ("position" in searchFrom) {
2547
+ args = args.concat("FROMLONLAT", searchFrom.position.longitude.toString(), searchFrom.position.latitude.toString());
2548
+ }
2549
+ else {
2550
+ args = args.concat("FROMMEMBER", searchFrom.member);
2551
+ }
2552
+ if ("radius" in searchBy) {
2553
+ args = args.concat("BYRADIUS", searchBy.radius.toString(), searchBy.unit);
2554
+ }
2555
+ else {
2556
+ args = args.concat("BYBOX", searchBy.width.toString(), searchBy.height.toString(), searchBy.unit);
2557
+ }
2558
+ if (resultOptions) {
2559
+ if ("withCoord" in resultOptions &&
2560
+ resultOptions.withCoord)
2561
+ args.push("WITHCOORD");
2562
+ if ("withDist" in resultOptions &&
2563
+ resultOptions.withDist)
2564
+ args.push("WITHDIST");
2565
+ if ("withHash" in resultOptions &&
2566
+ resultOptions.withHash)
2567
+ args.push("WITHHASH");
2568
+ if ("storeDist" in resultOptions &&
2569
+ resultOptions.storeDist)
2570
+ args.push("STOREDIST");
2571
+ if (resultOptions.count) {
2572
+ args.push("COUNT", resultOptions.count?.toString());
2573
+ if (resultOptions.isAny)
2574
+ args.push("ANY");
2575
+ }
2576
+ if (resultOptions.sortOrder)
2577
+ args.push(resultOptions.sortOrder);
2578
+ }
2579
+ return args;
2580
+ }
2581
+ /**
2582
+ * @internal
2583
+ */
2584
+ function createZRevRank(key, member) {
2585
+ return createCommand(RequestType.ZRevRank, [key, member]);
2586
+ }
2587
+ /**
2588
+ * @internal
2589
+ */
2590
+ function createZRevRankWithScore(key, member) {
2591
+ return createCommand(RequestType.ZRevRank, [key, member, "WITHSCORE"]);
2592
+ }
2593
+ /**
2594
+ * Mandatory option for zmpop.
2595
+ * Defines which elements to pop from the sorted set.
2596
+ */
2597
+ var ScoreFilter;
2598
+ (function (ScoreFilter) {
2599
+ /** Pop elements with the highest scores. */
2600
+ ScoreFilter["MAX"] = "MAX";
2601
+ /** Pop elements with the lowest scores. */
2602
+ ScoreFilter["MIN"] = "MIN";
2603
+ })(ScoreFilter || (exports.ScoreFilter = ScoreFilter = {}));
2604
+ /**
2605
+ * @internal
2606
+ */
2607
+ function createZMPop(keys, modifier, count) {
2608
+ const args = keys;
2609
+ args.unshift(keys.length.toString());
2610
+ args.push(modifier);
2611
+ if (count !== undefined) {
2612
+ args.push("COUNT");
2613
+ args.push(count.toString());
2614
+ }
2615
+ return createCommand(RequestType.ZMPop, args);
2616
+ }
2617
+ /**
2618
+ * @internal
2619
+ */
2620
+ function createBZMPop(keys, modifier, timeout, count) {
2621
+ const args = [
2622
+ timeout.toString(),
2623
+ keys.length.toString(),
2624
+ ...keys,
2625
+ modifier,
2626
+ ];
2627
+ if (count !== undefined) {
2628
+ args.push("COUNT");
2629
+ args.push(count.toString());
2630
+ }
2631
+ return createCommand(RequestType.BZMPop, args);
2632
+ }
2633
+ /**
2634
+ * @internal
2635
+ */
2636
+ function createZIncrBy(key, increment, member) {
2637
+ return createCommand(RequestType.ZIncrBy, [
2638
+ key,
2639
+ increment.toString(),
2640
+ member,
2641
+ ]);
2642
+ }
2643
+ /** @internal */
2644
+ function createSort(key, options, destination) {
2645
+ return createSortImpl(RequestType.Sort, key, options, destination);
2646
+ }
2647
+ /** @internal */
2648
+ function createSortReadOnly(key, options) {
2649
+ return createSortImpl(RequestType.SortReadOnly, key, options);
2650
+ }
2651
+ /** @internal */
2652
+ function createSortImpl(cmd, key, options, destination) {
2653
+ const args = [key];
2654
+ if (options) {
2655
+ if (options.limit) {
2656
+ args.push("LIMIT", options.limit.offset.toString(), options.limit.count.toString());
2657
+ }
2658
+ if (options.orderBy) {
2659
+ args.push(options.orderBy);
2660
+ }
2661
+ if (options.isAlpha) {
2662
+ args.push("ALPHA");
2663
+ }
2664
+ if (options.byPattern) {
2665
+ args.push("BY", options.byPattern);
2666
+ }
2667
+ if (options.getPatterns) {
2668
+ options.getPatterns.forEach((p) => args.push("GET", p));
2669
+ }
2670
+ }
2671
+ if (destination)
2672
+ args.push("STORE", destination);
2673
+ return createCommand(cmd, args);
2674
+ }
2675
+ /**
2676
+ * @internal
2677
+ */
2678
+ function createHStrlen(key, field) {
2679
+ return createCommand(RequestType.HStrlen, [key, field]);
2680
+ }
2681
+ /** @internal */
2682
+ function createHRandField(key, count, withValues) {
2683
+ const args = [key];
2684
+ if (count !== undefined)
2685
+ args.push(count.toString());
2686
+ if (withValues)
2687
+ args.push("WITHVALUES");
2688
+ return createCommand(RequestType.HRandField, args);
2689
+ }
2690
+ /**
2691
+ * @internal
2692
+ */
2693
+ function createHScan(key, cursor, options) {
2694
+ let args = [key, cursor];
2695
+ if (options) {
2696
+ args = args.concat(convertBaseScanOptionsToArgsArray(options));
2697
+ if (options.noValues) {
2698
+ args.push("NOVALUES");
2699
+ }
2700
+ }
2701
+ return createCommand(RequestType.HScan, args);
2702
+ }
2703
+ /**
2704
+ * @internal
2705
+ */
2706
+ function createZRandMember(key, count, withscores) {
2707
+ const args = [key];
2708
+ if (count !== undefined) {
2709
+ args.push(count.toString());
2710
+ }
2711
+ if (withscores) {
2712
+ args.push("WITHSCORES");
2713
+ }
2714
+ return createCommand(RequestType.ZRandMember, args);
2715
+ }
2716
+ /** @internal */
2717
+ function createLastSave() {
2718
+ return createCommand(RequestType.LastSave, []);
2719
+ }
2720
+ /** @internal */
2721
+ function createLCS(key1, key2, options) {
2722
+ const args = [key1, key2];
2723
+ if (options) {
2724
+ if (options.len)
2725
+ args.push("LEN");
2726
+ else if (options.idx) {
2727
+ args.push("IDX");
2728
+ if (options.idx.withMatchLen)
2729
+ args.push("WITHMATCHLEN");
2730
+ if (options.idx.minMatchLen !== undefined)
2731
+ args.push("MINMATCHLEN", options.idx.minMatchLen.toString());
2732
+ }
2733
+ }
2734
+ return createCommand(RequestType.LCS, args);
2735
+ }
2736
+ /**
2737
+ * @internal
2738
+ */
2739
+ function createTouch(keys) {
2740
+ return createCommand(RequestType.Touch, keys);
2741
+ }
2742
+ /** @internal */
2743
+ function createRandomKey() {
2744
+ return createCommand(RequestType.RandomKey, []);
2745
+ }
2746
+ /** @internal */
2747
+ function createWatch(keys) {
2748
+ return createCommand(RequestType.Watch, keys);
2749
+ }
2750
+ /** @internal */
2751
+ function createUnWatch() {
2752
+ return createCommand(RequestType.UnWatch, []);
2753
+ }
2754
+ /** @internal */
2755
+ function createWait(numreplicas, timeout) {
2756
+ return createCommand(RequestType.Wait, [
2757
+ numreplicas.toString(),
2758
+ timeout.toString(),
2759
+ ]);
2760
+ }
2761
+ /**
2762
+ * @internal
2763
+ */
2764
+ function convertBaseScanOptionsToArgsArray(options) {
2765
+ const args = [];
2766
+ if (options.match) {
2767
+ args.push("MATCH", options.match);
2768
+ }
2769
+ if (options.count !== undefined) {
2770
+ args.push("COUNT", options.count.toString());
2771
+ }
2772
+ return args;
2773
+ }
2774
+ /**
2775
+ * @internal
2776
+ */
2777
+ function createZScan(key, cursor, options) {
2778
+ let args = [key, cursor];
2779
+ if (options) {
2780
+ args = args.concat(convertBaseScanOptionsToArgsArray(options));
2781
+ if (options.noScores) {
2782
+ args.push("NOSCORES");
2783
+ }
2784
+ }
2785
+ return createCommand(RequestType.ZScan, args);
2786
+ }
2787
+ /** @internal */
2788
+ function createSetRange(key, offset, value) {
2789
+ return createCommand(RequestType.SetRange, [key, offset.toString(), value]);
2790
+ }
2791
+ /** @internal */
2792
+ function createAppend(key, value) {
2793
+ return createCommand(RequestType.Append, [key, value]);
2794
+ }
2795
+ /**
2796
+ * @internal
2797
+ */
2798
+ function createLMPop(keys, direction, count) {
2799
+ const args = [keys.length.toString(), ...keys, direction];
2800
+ if (count !== undefined) {
2801
+ args.push("COUNT");
2802
+ args.push(count.toString());
2803
+ }
2804
+ return createCommand(RequestType.LMPop, args);
2805
+ }
2806
+ /**
2807
+ * @internal
2808
+ */
2809
+ function createBLMPop(keys, direction, timeout, count) {
2810
+ const args = [
2811
+ timeout.toString(),
2812
+ keys.length.toString(),
2813
+ ...keys,
2814
+ direction,
2815
+ ];
2816
+ if (count !== undefined) {
2817
+ args.push("COUNT");
2818
+ args.push(count.toString());
2819
+ }
2820
+ return createCommand(RequestType.BLMPop, args);
2821
+ }
2822
+ /**
2823
+ * @internal
2824
+ */
2825
+ function createPubSubChannels(pattern) {
2826
+ return createCommand(RequestType.PubSubChannels, pattern ? [pattern] : []);
2827
+ }
2828
+ /**
2829
+ * @internal
2830
+ */
2831
+ function createPubSubNumPat() {
2832
+ return createCommand(RequestType.PubSubNumPat, []);
2833
+ }
2834
+ /**
2835
+ * @internal
2836
+ */
2837
+ function createPubSubNumSub(channels) {
2838
+ return createCommand(RequestType.PubSubNumSub, channels ? channels : []);
2839
+ }
2840
+ /**
2841
+ * @internal
2842
+ */
2843
+ function createPubsubShardChannels(pattern) {
2844
+ return createCommand(RequestType.PubSubShardChannels, pattern ? [pattern] : []);
2845
+ }
2846
+ /**
2847
+ * @internal
2848
+ */
2849
+ function createPubSubShardNumSub(channels) {
2850
+ return createCommand(RequestType.PubSubShardNumSub, channels ? channels : []);
2851
+ }
2852
+ /**
2853
+ * @internal
2854
+ */
2855
+ function createBZPopMax(keys, timeout) {
2856
+ return createCommand(RequestType.BZPopMax, [...keys, timeout.toString()]);
2857
+ }
2858
+ /**
2859
+ * @internal
2860
+ */
2861
+ function createBZPopMin(keys, timeout) {
2862
+ return createCommand(RequestType.BZPopMin, [...keys, timeout.toString()]);
2863
+ }
2864
+ /**
2865
+ * @internal
2866
+ */
2867
+ function createScriptShow(sha1) {
2868
+ return createCommand(RequestType.ScriptShow, [sha1]);
2869
+ }
2870
+ /**
2871
+ * Time unit representation which is used in optional arguments for {@link BaseClient.getex|getex} and {@link BaseClient.set|set} command.
2872
+ */
2873
+ var TimeUnit;
2874
+ (function (TimeUnit) {
2875
+ /**
2876
+ * Set the specified expire time, in seconds. Equivalent to
2877
+ * `EX` in the VALKEY API.
2878
+ */
2879
+ TimeUnit["Seconds"] = "EX";
2880
+ /**
2881
+ * Set the specified expire time, in milliseconds. Equivalent
2882
+ * to `PX` in the VALKEY API.
2883
+ */
2884
+ TimeUnit["Milliseconds"] = "PX";
2885
+ /**
2886
+ * Set the specified Unix time at which the key will expire,
2887
+ * in seconds. Equivalent to `EXAT` in the VALKEY API.
2888
+ */
2889
+ TimeUnit["UnixSeconds"] = "EXAT";
2890
+ /**
2891
+ * Set the specified Unix time at which the key will expire,
2892
+ * in milliseconds. Equivalent to `PXAT` in the VALKEY API.
2893
+ */
2894
+ TimeUnit["UnixMilliseconds"] = "PXAT";
2895
+ })(TimeUnit || (exports.TimeUnit = TimeUnit = {}));
2896
+ /**
2897
+ * @internal
2898
+ */
2899
+ function createGetEx(key, options) {
2900
+ const args = [key];
2901
+ if (options) {
2902
+ if (options !== "persist" && !Number.isInteger(options.duration)) {
2903
+ throw new Error(`Received expiry '${JSON.stringify(options.duration)}'. Count must be an integer`);
2904
+ }
2905
+ if (options === "persist") {
2906
+ args.push("PERSIST");
2907
+ }
2908
+ else {
2909
+ args.push(options.type, options.duration.toString());
2910
+ }
2911
+ }
2912
+ return createCommand(RequestType.GetEx, args);
2913
+ }
2914
+ /**
2915
+ * @internal
2916
+ */
2917
+ function createXAck(key, group, ids) {
2918
+ return createCommand(RequestType.XAck, [key, group, ...ids]);
2919
+ }
2920
+ /**
2921
+ * @internal
2922
+ */
2923
+ function createXGroupSetid(key, groupName, id, entriesRead) {
2924
+ const args = [key, groupName, id];
2925
+ if (entriesRead !== undefined) {
2926
+ args.push("ENTRIESREAD");
2927
+ args.push(entriesRead.toString());
2928
+ }
2929
+ return createCommand(RequestType.XGroupSetId, args);
2930
+ }
2931
+ /**
2932
+ * @internal
2933
+ */
2934
+ function createScriptExists(sha1s) {
2935
+ return createCommand(RequestType.ScriptExists, sha1s);
2936
+ }
2937
+ /**
2938
+ * @internal
2939
+ */
2940
+ function createScriptFlush(mode) {
2941
+ if (mode) {
2942
+ return createCommand(RequestType.ScriptFlush, [mode.toString()]);
2943
+ }
2944
+ else {
2945
+ return createCommand(RequestType.ScriptFlush, []);
2946
+ }
2947
+ }
2948
+ /** @internal */
2949
+ function createScriptKill() {
2950
+ return createCommand(RequestType.ScriptKill, []);
2951
+ }