@upstash/redis 0.0.0-ci.8895aca4ac4b6a7430f4e15b010a71fd1735c231-20240408001502 → 0.0.0-ci.893d5822fe6324e13932f920ba66e56179dfdb9f-20260130092901

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,4838 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // pkg/error.ts
8
+ var error_exports = {};
9
+ __export(error_exports, {
10
+ UpstashError: () => UpstashError,
11
+ UpstashJSONParseError: () => UpstashJSONParseError,
12
+ UrlError: () => UrlError
13
+ });
14
+ var UpstashError = class extends Error {
15
+ constructor(message, options) {
16
+ super(message, options);
17
+ this.name = "UpstashError";
18
+ }
19
+ };
20
+ var UrlError = class extends Error {
21
+ constructor(url) {
22
+ super(
23
+ `Upstash Redis client was passed an invalid URL. You should pass a URL starting with https. Received: "${url}". `
24
+ );
25
+ this.name = "UrlError";
26
+ }
27
+ };
28
+ var UpstashJSONParseError = class extends UpstashError {
29
+ constructor(body, options) {
30
+ const truncatedBody = body.length > 200 ? body.slice(0, 200) + "..." : body;
31
+ super(`Unable to parse response body: ${truncatedBody}`, options);
32
+ this.name = "UpstashJSONParseError";
33
+ }
34
+ };
35
+
36
+ // pkg/util.ts
37
+ function parseRecursive(obj) {
38
+ const parsed = Array.isArray(obj) ? obj.map((o) => {
39
+ try {
40
+ return parseRecursive(o);
41
+ } catch {
42
+ return o;
43
+ }
44
+ }) : JSON.parse(obj);
45
+ if (typeof parsed === "number" && parsed.toString() !== obj) {
46
+ return obj;
47
+ }
48
+ return parsed;
49
+ }
50
+ function parseResponse(result) {
51
+ try {
52
+ return parseRecursive(result);
53
+ } catch {
54
+ return result;
55
+ }
56
+ }
57
+ function deserializeScanResponse(result) {
58
+ return [result[0], ...parseResponse(result.slice(1))];
59
+ }
60
+ function deserializeScanWithTypesResponse(result) {
61
+ const [cursor, keys] = result;
62
+ const parsedKeys = [];
63
+ for (let i = 0; i < keys.length; i += 2) {
64
+ parsedKeys.push({ key: keys[i], type: keys[i + 1] });
65
+ }
66
+ return [cursor, parsedKeys];
67
+ }
68
+ function mergeHeaders(...headers) {
69
+ const merged = {};
70
+ for (const header of headers) {
71
+ if (!header) continue;
72
+ for (const [key, value] of Object.entries(header)) {
73
+ if (value !== void 0 && value !== null) {
74
+ merged[key] = value;
75
+ }
76
+ }
77
+ }
78
+ return merged;
79
+ }
80
+ function kvArrayToObject(v) {
81
+ if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
82
+ if (!Array.isArray(v)) return {};
83
+ const obj = {};
84
+ for (let i = 0; i < v.length; i += 2) {
85
+ if (typeof v[i] === "string") obj[v[i]] = v[i + 1];
86
+ }
87
+ return obj;
88
+ }
89
+
90
+ // pkg/http.ts
91
+ var MAX_BUFFER_SIZE = 1024 * 1024;
92
+ var HttpClient = class {
93
+ baseUrl;
94
+ headers;
95
+ options;
96
+ readYourWrites;
97
+ upstashSyncToken = "";
98
+ hasCredentials;
99
+ retry;
100
+ constructor(config) {
101
+ this.options = {
102
+ backend: config.options?.backend,
103
+ agent: config.agent,
104
+ responseEncoding: config.responseEncoding ?? "base64",
105
+ // default to base64
106
+ cache: config.cache,
107
+ signal: config.signal,
108
+ keepAlive: config.keepAlive ?? true
109
+ };
110
+ this.upstashSyncToken = "";
111
+ this.readYourWrites = config.readYourWrites ?? true;
112
+ this.baseUrl = (config.baseUrl || "").replace(/\/$/, "");
113
+ const urlRegex = /^https?:\/\/[^\s#$./?].\S*$/;
114
+ if (this.baseUrl && !urlRegex.test(this.baseUrl)) {
115
+ throw new UrlError(this.baseUrl);
116
+ }
117
+ this.headers = {
118
+ "Content-Type": "application/json",
119
+ ...config.headers
120
+ };
121
+ this.hasCredentials = Boolean(this.baseUrl && this.headers.authorization.split(" ")[1]);
122
+ if (this.options.responseEncoding === "base64") {
123
+ this.headers["Upstash-Encoding"] = "base64";
124
+ }
125
+ this.retry = typeof config.retry === "boolean" && !config.retry ? {
126
+ attempts: 1,
127
+ backoff: () => 0
128
+ } : {
129
+ attempts: config.retry?.retries ?? 5,
130
+ backoff: config.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
131
+ };
132
+ }
133
+ mergeTelemetry(telemetry) {
134
+ this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
135
+ this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
136
+ this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
137
+ }
138
+ async request(req) {
139
+ const requestHeaders = mergeHeaders(this.headers, req.headers ?? {});
140
+ const requestUrl = [this.baseUrl, ...req.path ?? []].join("/");
141
+ const isEventStream = requestHeaders.Accept === "text/event-stream";
142
+ const signal = req.signal ?? this.options.signal;
143
+ const isSignalFunction = typeof signal === "function";
144
+ const requestOptions = {
145
+ //@ts-expect-error this should throw due to bun regression
146
+ cache: this.options.cache,
147
+ method: "POST",
148
+ headers: requestHeaders,
149
+ body: JSON.stringify(req.body),
150
+ keepalive: this.options.keepAlive,
151
+ agent: this.options.agent,
152
+ signal: isSignalFunction ? signal() : signal,
153
+ /**
154
+ * Fastly specific
155
+ */
156
+ backend: this.options.backend
157
+ };
158
+ if (!this.hasCredentials) {
159
+ console.warn(
160
+ "[Upstash Redis] Redis client was initialized without url or token. Failed to execute command."
161
+ );
162
+ }
163
+ if (this.readYourWrites) {
164
+ const newHeader = this.upstashSyncToken;
165
+ this.headers["upstash-sync-token"] = newHeader;
166
+ }
167
+ let res = null;
168
+ let error = null;
169
+ for (let i = 0; i <= this.retry.attempts; i++) {
170
+ try {
171
+ res = await fetch(requestUrl, requestOptions);
172
+ break;
173
+ } catch (error_) {
174
+ if (requestOptions.signal?.aborted && isSignalFunction) {
175
+ throw error_;
176
+ } else if (requestOptions.signal?.aborted) {
177
+ const myBlob = new Blob([
178
+ JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
179
+ ]);
180
+ const myOptions = {
181
+ status: 200,
182
+ statusText: requestOptions.signal.reason ?? "Aborted"
183
+ };
184
+ res = new Response(myBlob, myOptions);
185
+ break;
186
+ }
187
+ error = error_;
188
+ if (i < this.retry.attempts) {
189
+ await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
190
+ }
191
+ }
192
+ }
193
+ if (!res) {
194
+ throw error ?? new Error("Exhausted all retries");
195
+ }
196
+ if (!res.ok) {
197
+ let body2;
198
+ const rawBody2 = await res.text();
199
+ try {
200
+ body2 = JSON.parse(rawBody2);
201
+ } catch (error2) {
202
+ throw new UpstashJSONParseError(rawBody2, { cause: error2 });
203
+ }
204
+ throw new UpstashError(`${body2.error}, command was: ${JSON.stringify(req.body)}`);
205
+ }
206
+ if (this.readYourWrites) {
207
+ const headers = res.headers;
208
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
209
+ }
210
+ if (isEventStream && req && req.onMessage && res.body) {
211
+ const reader = res.body.getReader();
212
+ const decoder = new TextDecoder();
213
+ (async () => {
214
+ try {
215
+ let buffer = "";
216
+ while (true) {
217
+ const { value, done } = await reader.read();
218
+ if (done) break;
219
+ buffer += decoder.decode(value, { stream: true });
220
+ const lines = buffer.split("\n");
221
+ buffer = lines.pop() || "";
222
+ if (buffer.length > MAX_BUFFER_SIZE) {
223
+ throw new Error("Buffer size exceeded (1MB)");
224
+ }
225
+ for (const line of lines) {
226
+ if (line.startsWith("data: ")) {
227
+ const data = line.slice(6);
228
+ req.onMessage?.(data);
229
+ }
230
+ }
231
+ }
232
+ } catch (error2) {
233
+ if (error2 instanceof Error && error2.name === "AbortError") {
234
+ } else {
235
+ console.error("Stream reading error:", error2);
236
+ }
237
+ } finally {
238
+ try {
239
+ await reader.cancel();
240
+ } catch {
241
+ }
242
+ }
243
+ })();
244
+ return { result: 1 };
245
+ }
246
+ let body;
247
+ const rawBody = await res.text();
248
+ try {
249
+ body = JSON.parse(rawBody);
250
+ } catch (error2) {
251
+ throw new UpstashJSONParseError(rawBody, { cause: error2 });
252
+ }
253
+ if (this.readYourWrites) {
254
+ const headers = res.headers;
255
+ this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
256
+ }
257
+ if (this.options.responseEncoding === "base64") {
258
+ if (Array.isArray(body)) {
259
+ return body.map(({ result: result2, error: error2 }) => ({
260
+ result: decode(result2),
261
+ error: error2
262
+ }));
263
+ }
264
+ const result = decode(body.result);
265
+ return { result, error: body.error };
266
+ }
267
+ return body;
268
+ }
269
+ };
270
+ function base64decode(b64) {
271
+ let dec = "";
272
+ try {
273
+ const binString = atob(b64);
274
+ const size = binString.length;
275
+ const bytes = new Uint8Array(size);
276
+ for (let i = 0; i < size; i++) {
277
+ bytes[i] = binString.charCodeAt(i);
278
+ }
279
+ dec = new TextDecoder().decode(bytes);
280
+ } catch {
281
+ dec = b64;
282
+ }
283
+ return dec;
284
+ }
285
+ function decode(raw) {
286
+ let result = void 0;
287
+ switch (typeof raw) {
288
+ case "undefined": {
289
+ return raw;
290
+ }
291
+ case "number": {
292
+ result = raw;
293
+ break;
294
+ }
295
+ case "object": {
296
+ if (Array.isArray(raw)) {
297
+ result = raw.map(
298
+ (v) => typeof v === "string" ? base64decode(v) : Array.isArray(v) ? v.map((element) => decode(element)) : v
299
+ );
300
+ } else {
301
+ result = null;
302
+ }
303
+ break;
304
+ }
305
+ case "string": {
306
+ result = raw === "OK" ? "OK" : base64decode(raw);
307
+ break;
308
+ }
309
+ default: {
310
+ break;
311
+ }
312
+ }
313
+ return result;
314
+ }
315
+ function merge(obj, key, value) {
316
+ if (!value) {
317
+ return obj;
318
+ }
319
+ obj[key] = obj[key] ? [obj[key], value].join(",") : value;
320
+ return obj;
321
+ }
322
+
323
+ // pkg/commands/command.ts
324
+ var defaultSerializer = (c) => {
325
+ switch (typeof c) {
326
+ case "string":
327
+ case "number":
328
+ case "boolean": {
329
+ return c;
330
+ }
331
+ default: {
332
+ return JSON.stringify(c);
333
+ }
334
+ }
335
+ };
336
+ var Command = class {
337
+ command;
338
+ serialize;
339
+ deserialize;
340
+ headers;
341
+ path;
342
+ onMessage;
343
+ isStreaming;
344
+ signal;
345
+ /**
346
+ * Create a new command instance.
347
+ *
348
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
349
+ */
350
+ constructor(command, opts) {
351
+ this.serialize = defaultSerializer;
352
+ this.deserialize = opts?.automaticDeserialization === void 0 || opts.automaticDeserialization ? opts?.deserialize ?? parseResponse : (x) => x;
353
+ this.command = command.map((c) => this.serialize(c));
354
+ this.headers = opts?.headers;
355
+ this.path = opts?.path;
356
+ this.onMessage = opts?.streamOptions?.onMessage;
357
+ this.isStreaming = opts?.streamOptions?.isStreaming ?? false;
358
+ this.signal = opts?.streamOptions?.signal;
359
+ if (opts?.latencyLogging) {
360
+ const originalExec = this.exec.bind(this);
361
+ this.exec = async (client) => {
362
+ const start = performance.now();
363
+ const result = await originalExec(client);
364
+ const end = performance.now();
365
+ const loggerResult = (end - start).toFixed(2);
366
+ console.log(
367
+ `Latency for \x1B[38;2;19;185;39m${this.command[0].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
368
+ );
369
+ return result;
370
+ };
371
+ }
372
+ }
373
+ /**
374
+ * Execute the command using a client.
375
+ */
376
+ async exec(client) {
377
+ const { result, error } = await client.request({
378
+ body: this.command,
379
+ path: this.path,
380
+ upstashSyncToken: client.upstashSyncToken,
381
+ headers: this.headers,
382
+ onMessage: this.onMessage,
383
+ isStreaming: this.isStreaming,
384
+ signal: this.signal
385
+ });
386
+ if (error) {
387
+ throw new UpstashError(error);
388
+ }
389
+ if (result === void 0) {
390
+ throw new TypeError("Request did not return a result");
391
+ }
392
+ return this.deserialize(result);
393
+ }
394
+ };
395
+
396
+ // pkg/commands/hrandfield.ts
397
+ function deserialize(result) {
398
+ if (result.length === 0) {
399
+ return null;
400
+ }
401
+ const obj = {};
402
+ for (let i = 0; i < result.length; i += 2) {
403
+ const key = result[i];
404
+ const value = result[i + 1];
405
+ try {
406
+ obj[key] = JSON.parse(value);
407
+ } catch {
408
+ obj[key] = value;
409
+ }
410
+ }
411
+ return obj;
412
+ }
413
+ var HRandFieldCommand = class extends Command {
414
+ constructor(cmd, opts) {
415
+ const command = ["hrandfield", cmd[0]];
416
+ if (typeof cmd[1] === "number") {
417
+ command.push(cmd[1]);
418
+ }
419
+ if (cmd[2]) {
420
+ command.push("WITHVALUES");
421
+ }
422
+ super(command, {
423
+ // @ts-expect-error to silence compiler
424
+ deserialize: cmd[2] ? (result) => deserialize(result) : opts?.deserialize,
425
+ ...opts
426
+ });
427
+ }
428
+ };
429
+
430
+ // pkg/commands/append.ts
431
+ var AppendCommand = class extends Command {
432
+ constructor(cmd, opts) {
433
+ super(["append", ...cmd], opts);
434
+ }
435
+ };
436
+
437
+ // pkg/commands/bitcount.ts
438
+ var BitCountCommand = class extends Command {
439
+ constructor([key, start, end], opts) {
440
+ const command = ["bitcount", key];
441
+ if (typeof start === "number") {
442
+ command.push(start);
443
+ }
444
+ if (typeof end === "number") {
445
+ command.push(end);
446
+ }
447
+ super(command, opts);
448
+ }
449
+ };
450
+
451
+ // pkg/commands/bitfield.ts
452
+ var BitFieldCommand = class {
453
+ constructor(args, client, opts, execOperation = (command) => command.exec(this.client)) {
454
+ this.client = client;
455
+ this.opts = opts;
456
+ this.execOperation = execOperation;
457
+ this.command = ["bitfield", ...args];
458
+ }
459
+ command;
460
+ chain(...args) {
461
+ this.command.push(...args);
462
+ return this;
463
+ }
464
+ get(...args) {
465
+ return this.chain("get", ...args);
466
+ }
467
+ set(...args) {
468
+ return this.chain("set", ...args);
469
+ }
470
+ incrby(...args) {
471
+ return this.chain("incrby", ...args);
472
+ }
473
+ overflow(overflow) {
474
+ return this.chain("overflow", overflow);
475
+ }
476
+ exec() {
477
+ const command = new Command(this.command, this.opts);
478
+ return this.execOperation(command);
479
+ }
480
+ };
481
+
482
+ // pkg/commands/bitop.ts
483
+ var BitOpCommand = class extends Command {
484
+ constructor(cmd, opts) {
485
+ super(["bitop", ...cmd], opts);
486
+ }
487
+ };
488
+
489
+ // pkg/commands/bitpos.ts
490
+ var BitPosCommand = class extends Command {
491
+ constructor(cmd, opts) {
492
+ super(["bitpos", ...cmd], opts);
493
+ }
494
+ };
495
+
496
+ // pkg/commands/client_setinfo.ts
497
+ var ClientSetInfoCommand = class extends Command {
498
+ constructor([attribute, value], opts) {
499
+ super(["CLIENT", "SETINFO", attribute.toUpperCase(), value], opts);
500
+ }
501
+ };
502
+
503
+ // pkg/commands/copy.ts
504
+ var CopyCommand = class extends Command {
505
+ constructor([key, destinationKey, opts], commandOptions) {
506
+ super(["COPY", key, destinationKey, ...opts?.replace ? ["REPLACE"] : []], {
507
+ ...commandOptions,
508
+ deserialize(result) {
509
+ if (result > 0) {
510
+ return "COPIED";
511
+ }
512
+ return "NOT_COPIED";
513
+ }
514
+ });
515
+ }
516
+ };
517
+
518
+ // pkg/commands/dbsize.ts
519
+ var DBSizeCommand = class extends Command {
520
+ constructor(opts) {
521
+ super(["dbsize"], opts);
522
+ }
523
+ };
524
+
525
+ // pkg/commands/decr.ts
526
+ var DecrCommand = class extends Command {
527
+ constructor(cmd, opts) {
528
+ super(["decr", ...cmd], opts);
529
+ }
530
+ };
531
+
532
+ // pkg/commands/decrby.ts
533
+ var DecrByCommand = class extends Command {
534
+ constructor(cmd, opts) {
535
+ super(["decrby", ...cmd], opts);
536
+ }
537
+ };
538
+
539
+ // pkg/commands/del.ts
540
+ var DelCommand = class extends Command {
541
+ constructor(cmd, opts) {
542
+ super(["del", ...cmd], opts);
543
+ }
544
+ };
545
+
546
+ // pkg/commands/echo.ts
547
+ var EchoCommand = class extends Command {
548
+ constructor(cmd, opts) {
549
+ super(["echo", ...cmd], opts);
550
+ }
551
+ };
552
+
553
+ // pkg/commands/evalRo.ts
554
+ var EvalROCommand = class extends Command {
555
+ constructor([script, keys, args], opts) {
556
+ super(["eval_ro", script, keys.length, ...keys, ...args ?? []], opts);
557
+ }
558
+ };
559
+
560
+ // pkg/commands/eval.ts
561
+ var EvalCommand = class extends Command {
562
+ constructor([script, keys, args], opts) {
563
+ super(["eval", script, keys.length, ...keys, ...args ?? []], opts);
564
+ }
565
+ };
566
+
567
+ // pkg/commands/evalshaRo.ts
568
+ var EvalshaROCommand = class extends Command {
569
+ constructor([sha, keys, args], opts) {
570
+ super(["evalsha_ro", sha, keys.length, ...keys, ...args ?? []], opts);
571
+ }
572
+ };
573
+
574
+ // pkg/commands/evalsha.ts
575
+ var EvalshaCommand = class extends Command {
576
+ constructor([sha, keys, args], opts) {
577
+ super(["evalsha", sha, keys.length, ...keys, ...args ?? []], opts);
578
+ }
579
+ };
580
+
581
+ // pkg/commands/exec.ts
582
+ var ExecCommand = class extends Command {
583
+ constructor(cmd, opts) {
584
+ const normalizedCmd = cmd.map((arg) => typeof arg === "string" ? arg : String(arg));
585
+ super(normalizedCmd, opts);
586
+ }
587
+ };
588
+
589
+ // pkg/commands/exists.ts
590
+ var ExistsCommand = class extends Command {
591
+ constructor(cmd, opts) {
592
+ super(["exists", ...cmd], opts);
593
+ }
594
+ };
595
+
596
+ // pkg/commands/expire.ts
597
+ var ExpireCommand = class extends Command {
598
+ constructor(cmd, opts) {
599
+ super(["expire", ...cmd.filter(Boolean)], opts);
600
+ }
601
+ };
602
+
603
+ // pkg/commands/expireat.ts
604
+ var ExpireAtCommand = class extends Command {
605
+ constructor(cmd, opts) {
606
+ super(["expireat", ...cmd], opts);
607
+ }
608
+ };
609
+
610
+ // pkg/commands/fcall.ts
611
+ var FCallCommand = class extends Command {
612
+ constructor([functionName, keys, args], opts) {
613
+ super(["fcall", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []], opts);
614
+ }
615
+ };
616
+
617
+ // pkg/commands/fcall_ro.ts
618
+ var FCallRoCommand = class extends Command {
619
+ constructor([functionName, keys, args], opts) {
620
+ super(
621
+ ["fcall_ro", functionName, ...keys ? [keys.length, ...keys] : [0], ...args ?? []],
622
+ opts
623
+ );
624
+ }
625
+ };
626
+
627
+ // pkg/commands/flushall.ts
628
+ var FlushAllCommand = class extends Command {
629
+ constructor(args, opts) {
630
+ const command = ["flushall"];
631
+ if (args && args.length > 0 && args[0].async) {
632
+ command.push("async");
633
+ }
634
+ super(command, opts);
635
+ }
636
+ };
637
+
638
+ // pkg/commands/flushdb.ts
639
+ var FlushDBCommand = class extends Command {
640
+ constructor([opts], cmdOpts) {
641
+ const command = ["flushdb"];
642
+ if (opts?.async) {
643
+ command.push("async");
644
+ }
645
+ super(command, cmdOpts);
646
+ }
647
+ };
648
+
649
+ // pkg/commands/function_delete.ts
650
+ var FunctionDeleteCommand = class extends Command {
651
+ constructor([libraryName], opts) {
652
+ super(["function", "delete", libraryName], opts);
653
+ }
654
+ };
655
+
656
+ // pkg/commands/function_flush.ts
657
+ var FunctionFlushCommand = class extends Command {
658
+ constructor(opts) {
659
+ super(["function", "flush"], opts);
660
+ }
661
+ };
662
+
663
+ // pkg/commands/function_list.ts
664
+ var FunctionListCommand = class extends Command {
665
+ constructor([args], opts) {
666
+ const command = ["function", "list"];
667
+ if (args?.libraryName) {
668
+ command.push("libraryname", args.libraryName);
669
+ }
670
+ if (args?.withCode) {
671
+ command.push("withcode");
672
+ }
673
+ super(command, { deserialize: deserialize2, ...opts });
674
+ }
675
+ };
676
+ function deserialize2(result) {
677
+ if (!Array.isArray(result)) return [];
678
+ return result.map((libRaw) => {
679
+ const lib = kvArrayToObject(libRaw);
680
+ const functionsParsed = lib.functions.map(
681
+ (fnRaw) => kvArrayToObject(fnRaw)
682
+ );
683
+ return {
684
+ libraryName: lib.library_name,
685
+ engine: lib.engine,
686
+ functions: functionsParsed.map((fn) => ({
687
+ name: fn.name,
688
+ description: fn.description ?? void 0,
689
+ flags: fn.flags
690
+ })),
691
+ libraryCode: lib.library_code
692
+ };
693
+ });
694
+ }
695
+
696
+ // pkg/commands/function_load.ts
697
+ var FunctionLoadCommand = class extends Command {
698
+ constructor([args], opts) {
699
+ super(["function", "load", ...args.replace ? ["replace"] : [], args.code], opts);
700
+ }
701
+ };
702
+
703
+ // pkg/commands/function_stats.ts
704
+ var FunctionStatsCommand = class extends Command {
705
+ constructor(opts) {
706
+ super(["function", "stats"], { deserialize: deserialize3, ...opts });
707
+ }
708
+ };
709
+ function deserialize3(result) {
710
+ const rawEngines = kvArrayToObject(kvArrayToObject(result).engines);
711
+ const parsedEngines = Object.fromEntries(
712
+ Object.entries(rawEngines).map(([key, value]) => [key, kvArrayToObject(value)])
713
+ );
714
+ const final = {
715
+ engines: Object.fromEntries(
716
+ Object.entries(parsedEngines).map(([key, value]) => [
717
+ key,
718
+ {
719
+ librariesCount: value.libraries_count,
720
+ functionsCount: value.functions_count
721
+ }
722
+ ])
723
+ )
724
+ };
725
+ return final;
726
+ }
727
+
728
+ // pkg/commands/geo_add.ts
729
+ var GeoAddCommand = class extends Command {
730
+ constructor([key, arg1, ...arg2], opts) {
731
+ const command = ["geoadd", key];
732
+ if ("nx" in arg1 && arg1.nx) {
733
+ command.push("nx");
734
+ } else if ("xx" in arg1 && arg1.xx) {
735
+ command.push("xx");
736
+ }
737
+ if ("ch" in arg1 && arg1.ch) {
738
+ command.push("ch");
739
+ }
740
+ if ("latitude" in arg1 && arg1.latitude) {
741
+ command.push(arg1.longitude, arg1.latitude, arg1.member);
742
+ }
743
+ command.push(
744
+ ...arg2.flatMap(({ latitude, longitude, member }) => [longitude, latitude, member])
745
+ );
746
+ super(command, opts);
747
+ }
748
+ };
749
+
750
+ // pkg/commands/geo_dist.ts
751
+ var GeoDistCommand = class extends Command {
752
+ constructor([key, member1, member2, unit = "M"], opts) {
753
+ super(["GEODIST", key, member1, member2, unit], opts);
754
+ }
755
+ };
756
+
757
+ // pkg/commands/geo_hash.ts
758
+ var GeoHashCommand = class extends Command {
759
+ constructor(cmd, opts) {
760
+ const [key] = cmd;
761
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
762
+ super(["GEOHASH", key, ...members], opts);
763
+ }
764
+ };
765
+
766
+ // pkg/commands/geo_pos.ts
767
+ var GeoPosCommand = class extends Command {
768
+ constructor(cmd, opts) {
769
+ const [key] = cmd;
770
+ const members = Array.isArray(cmd[1]) ? cmd[1] : cmd.slice(1);
771
+ super(["GEOPOS", key, ...members], {
772
+ deserialize: (result) => transform(result),
773
+ ...opts
774
+ });
775
+ }
776
+ };
777
+ function transform(result) {
778
+ const final = [];
779
+ for (const pos of result) {
780
+ if (!pos?.[0] || !pos?.[1]) {
781
+ continue;
782
+ }
783
+ final.push({ lng: Number.parseFloat(pos[0]), lat: Number.parseFloat(pos[1]) });
784
+ }
785
+ return final;
786
+ }
787
+
788
+ // pkg/commands/geo_search.ts
789
+ var GeoSearchCommand = class extends Command {
790
+ constructor([key, centerPoint, shape, order, opts], commandOptions) {
791
+ const command = ["GEOSEARCH", key];
792
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
793
+ command.push(centerPoint.type, centerPoint.member);
794
+ }
795
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
796
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
797
+ }
798
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
799
+ command.push(shape.type, shape.radius, shape.radiusType);
800
+ }
801
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
802
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
803
+ }
804
+ command.push(order);
805
+ if (opts?.count) {
806
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
807
+ }
808
+ const transform2 = (result) => {
809
+ if (!opts?.withCoord && !opts?.withDist && !opts?.withHash) {
810
+ return result.map((member) => {
811
+ try {
812
+ return { member: JSON.parse(member) };
813
+ } catch {
814
+ return { member };
815
+ }
816
+ });
817
+ }
818
+ return result.map((members) => {
819
+ let counter = 1;
820
+ const obj = {};
821
+ try {
822
+ obj.member = JSON.parse(members[0]);
823
+ } catch {
824
+ obj.member = members[0];
825
+ }
826
+ if (opts.withDist) {
827
+ obj.dist = Number.parseFloat(members[counter++]);
828
+ }
829
+ if (opts.withHash) {
830
+ obj.hash = members[counter++].toString();
831
+ }
832
+ if (opts.withCoord) {
833
+ obj.coord = {
834
+ long: Number.parseFloat(members[counter][0]),
835
+ lat: Number.parseFloat(members[counter][1])
836
+ };
837
+ }
838
+ return obj;
839
+ });
840
+ };
841
+ super(
842
+ [
843
+ ...command,
844
+ ...opts?.withCoord ? ["WITHCOORD"] : [],
845
+ ...opts?.withDist ? ["WITHDIST"] : [],
846
+ ...opts?.withHash ? ["WITHHASH"] : []
847
+ ],
848
+ {
849
+ deserialize: transform2,
850
+ ...commandOptions
851
+ }
852
+ );
853
+ }
854
+ };
855
+
856
+ // pkg/commands/geo_search_store.ts
857
+ var GeoSearchStoreCommand = class extends Command {
858
+ constructor([destination, key, centerPoint, shape, order, opts], commandOptions) {
859
+ const command = ["GEOSEARCHSTORE", destination, key];
860
+ if (centerPoint.type === "FROMMEMBER" || centerPoint.type === "frommember") {
861
+ command.push(centerPoint.type, centerPoint.member);
862
+ }
863
+ if (centerPoint.type === "FROMLONLAT" || centerPoint.type === "fromlonlat") {
864
+ command.push(centerPoint.type, centerPoint.coordinate.lon, centerPoint.coordinate.lat);
865
+ }
866
+ if (shape.type === "BYRADIUS" || shape.type === "byradius") {
867
+ command.push(shape.type, shape.radius, shape.radiusType);
868
+ }
869
+ if (shape.type === "BYBOX" || shape.type === "bybox") {
870
+ command.push(shape.type, shape.rect.width, shape.rect.height, shape.rectType);
871
+ }
872
+ command.push(order);
873
+ if (opts?.count) {
874
+ command.push("COUNT", opts.count.limit, ...opts.count.any ? ["ANY"] : []);
875
+ }
876
+ super([...command, ...opts?.storeDist ? ["STOREDIST"] : []], commandOptions);
877
+ }
878
+ };
879
+
880
+ // pkg/commands/get.ts
881
+ var GetCommand = class extends Command {
882
+ constructor(cmd, opts) {
883
+ super(["get", ...cmd], opts);
884
+ }
885
+ };
886
+
887
+ // pkg/commands/getbit.ts
888
+ var GetBitCommand = class extends Command {
889
+ constructor(cmd, opts) {
890
+ super(["getbit", ...cmd], opts);
891
+ }
892
+ };
893
+
894
+ // pkg/commands/getdel.ts
895
+ var GetDelCommand = class extends Command {
896
+ constructor(cmd, opts) {
897
+ super(["getdel", ...cmd], opts);
898
+ }
899
+ };
900
+
901
+ // pkg/commands/getex.ts
902
+ var GetExCommand = class extends Command {
903
+ constructor([key, opts], cmdOpts) {
904
+ const command = ["getex", key];
905
+ if (opts) {
906
+ if ("ex" in opts && typeof opts.ex === "number") {
907
+ command.push("ex", opts.ex);
908
+ } else if ("px" in opts && typeof opts.px === "number") {
909
+ command.push("px", opts.px);
910
+ } else if ("exat" in opts && typeof opts.exat === "number") {
911
+ command.push("exat", opts.exat);
912
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
913
+ command.push("pxat", opts.pxat);
914
+ } else if ("persist" in opts && opts.persist) {
915
+ command.push("persist");
916
+ }
917
+ }
918
+ super(command, cmdOpts);
919
+ }
920
+ };
921
+
922
+ // pkg/commands/getrange.ts
923
+ var GetRangeCommand = class extends Command {
924
+ constructor(cmd, opts) {
925
+ super(["getrange", ...cmd], opts);
926
+ }
927
+ };
928
+
929
+ // pkg/commands/getset.ts
930
+ var GetSetCommand = class extends Command {
931
+ constructor(cmd, opts) {
932
+ super(["getset", ...cmd], opts);
933
+ }
934
+ };
935
+
936
+ // pkg/commands/hdel.ts
937
+ var HDelCommand = class extends Command {
938
+ constructor(cmd, opts) {
939
+ super(["hdel", ...cmd], opts);
940
+ }
941
+ };
942
+
943
+ // pkg/commands/hexists.ts
944
+ var HExistsCommand = class extends Command {
945
+ constructor(cmd, opts) {
946
+ super(["hexists", ...cmd], opts);
947
+ }
948
+ };
949
+
950
+ // pkg/commands/hexpire.ts
951
+ var HExpireCommand = class extends Command {
952
+ constructor(cmd, opts) {
953
+ const [key, fields, seconds, option] = cmd;
954
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
955
+ super(
956
+ [
957
+ "hexpire",
958
+ key,
959
+ seconds,
960
+ ...option ? [option] : [],
961
+ "FIELDS",
962
+ fieldArray.length,
963
+ ...fieldArray
964
+ ],
965
+ opts
966
+ );
967
+ }
968
+ };
969
+
970
+ // pkg/commands/hexpireat.ts
971
+ var HExpireAtCommand = class extends Command {
972
+ constructor(cmd, opts) {
973
+ const [key, fields, timestamp, option] = cmd;
974
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
975
+ super(
976
+ [
977
+ "hexpireat",
978
+ key,
979
+ timestamp,
980
+ ...option ? [option] : [],
981
+ "FIELDS",
982
+ fieldArray.length,
983
+ ...fieldArray
984
+ ],
985
+ opts
986
+ );
987
+ }
988
+ };
989
+
990
+ // pkg/commands/hexpiretime.ts
991
+ var HExpireTimeCommand = class extends Command {
992
+ constructor(cmd, opts) {
993
+ const [key, fields] = cmd;
994
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
995
+ super(["hexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
996
+ }
997
+ };
998
+
999
+ // pkg/commands/hpersist.ts
1000
+ var HPersistCommand = class extends Command {
1001
+ constructor(cmd, opts) {
1002
+ const [key, fields] = cmd;
1003
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1004
+ super(["hpersist", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1005
+ }
1006
+ };
1007
+
1008
+ // pkg/commands/hpexpire.ts
1009
+ var HPExpireCommand = class extends Command {
1010
+ constructor(cmd, opts) {
1011
+ const [key, fields, milliseconds, option] = cmd;
1012
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1013
+ super(
1014
+ [
1015
+ "hpexpire",
1016
+ key,
1017
+ milliseconds,
1018
+ ...option ? [option] : [],
1019
+ "FIELDS",
1020
+ fieldArray.length,
1021
+ ...fieldArray
1022
+ ],
1023
+ opts
1024
+ );
1025
+ }
1026
+ };
1027
+
1028
+ // pkg/commands/hpexpireat.ts
1029
+ var HPExpireAtCommand = class extends Command {
1030
+ constructor(cmd, opts) {
1031
+ const [key, fields, timestamp, option] = cmd;
1032
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1033
+ super(
1034
+ [
1035
+ "hpexpireat",
1036
+ key,
1037
+ timestamp,
1038
+ ...option ? [option] : [],
1039
+ "FIELDS",
1040
+ fieldArray.length,
1041
+ ...fieldArray
1042
+ ],
1043
+ opts
1044
+ );
1045
+ }
1046
+ };
1047
+
1048
+ // pkg/commands/hpexpiretime.ts
1049
+ var HPExpireTimeCommand = class extends Command {
1050
+ constructor(cmd, opts) {
1051
+ const [key, fields] = cmd;
1052
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1053
+ super(["hpexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1054
+ }
1055
+ };
1056
+
1057
+ // pkg/commands/hpttl.ts
1058
+ var HPTtlCommand = class extends Command {
1059
+ constructor(cmd, opts) {
1060
+ const [key, fields] = cmd;
1061
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1062
+ super(["hpttl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1063
+ }
1064
+ };
1065
+
1066
+ // pkg/commands/hget.ts
1067
+ var HGetCommand = class extends Command {
1068
+ constructor(cmd, opts) {
1069
+ super(["hget", ...cmd], opts);
1070
+ }
1071
+ };
1072
+
1073
+ // pkg/commands/hgetall.ts
1074
+ function deserialize4(result) {
1075
+ if (result.length === 0) {
1076
+ return null;
1077
+ }
1078
+ const obj = {};
1079
+ for (let i = 0; i < result.length; i += 2) {
1080
+ const key = result[i];
1081
+ const value = result[i + 1];
1082
+ try {
1083
+ const valueIsNumberAndNotSafeInteger = !Number.isNaN(Number(value)) && !Number.isSafeInteger(Number(value));
1084
+ obj[key] = valueIsNumberAndNotSafeInteger ? value : JSON.parse(value);
1085
+ } catch {
1086
+ obj[key] = value;
1087
+ }
1088
+ }
1089
+ return obj;
1090
+ }
1091
+ var HGetAllCommand = class extends Command {
1092
+ constructor(cmd, opts) {
1093
+ super(["hgetall", ...cmd], {
1094
+ deserialize: (result) => deserialize4(result),
1095
+ ...opts
1096
+ });
1097
+ }
1098
+ };
1099
+
1100
+ // pkg/commands/hmget.ts
1101
+ function deserialize5(fields, result) {
1102
+ if (result.every((field) => field === null)) {
1103
+ return null;
1104
+ }
1105
+ const obj = {};
1106
+ for (const [i, field] of fields.entries()) {
1107
+ try {
1108
+ obj[field] = JSON.parse(result[i]);
1109
+ } catch {
1110
+ obj[field] = result[i];
1111
+ }
1112
+ }
1113
+ return obj;
1114
+ }
1115
+ var HMGetCommand = class extends Command {
1116
+ constructor([key, ...fields], opts) {
1117
+ super(["hmget", key, ...fields], {
1118
+ deserialize: (result) => deserialize5(fields, result),
1119
+ ...opts
1120
+ });
1121
+ }
1122
+ };
1123
+
1124
+ // pkg/commands/hgetdel.ts
1125
+ var HGetDelCommand = class extends Command {
1126
+ constructor([key, ...fields], opts) {
1127
+ super(["hgetdel", key, "FIELDS", fields.length, ...fields], {
1128
+ deserialize: (result) => deserialize5(fields.map(String), result),
1129
+ ...opts
1130
+ });
1131
+ }
1132
+ };
1133
+
1134
+ // pkg/commands/hgetex.ts
1135
+ var HGetExCommand = class extends Command {
1136
+ constructor([key, opts, ...fields], cmdOpts) {
1137
+ const command = ["hgetex", key];
1138
+ if ("ex" in opts && typeof opts.ex === "number") {
1139
+ command.push("EX", opts.ex);
1140
+ } else if ("px" in opts && typeof opts.px === "number") {
1141
+ command.push("PX", opts.px);
1142
+ } else if ("exat" in opts && typeof opts.exat === "number") {
1143
+ command.push("EXAT", opts.exat);
1144
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
1145
+ command.push("PXAT", opts.pxat);
1146
+ } else if ("persist" in opts && opts.persist) {
1147
+ command.push("PERSIST");
1148
+ }
1149
+ command.push("FIELDS", fields.length, ...fields);
1150
+ super(command, {
1151
+ deserialize: (result) => deserialize5(fields.map(String), result),
1152
+ ...cmdOpts
1153
+ });
1154
+ }
1155
+ };
1156
+
1157
+ // pkg/commands/hincrby.ts
1158
+ var HIncrByCommand = class extends Command {
1159
+ constructor(cmd, opts) {
1160
+ super(["hincrby", ...cmd], opts);
1161
+ }
1162
+ };
1163
+
1164
+ // pkg/commands/hincrbyfloat.ts
1165
+ var HIncrByFloatCommand = class extends Command {
1166
+ constructor(cmd, opts) {
1167
+ super(["hincrbyfloat", ...cmd], opts);
1168
+ }
1169
+ };
1170
+
1171
+ // pkg/commands/hkeys.ts
1172
+ var HKeysCommand = class extends Command {
1173
+ constructor([key], opts) {
1174
+ super(["hkeys", key], opts);
1175
+ }
1176
+ };
1177
+
1178
+ // pkg/commands/hlen.ts
1179
+ var HLenCommand = class extends Command {
1180
+ constructor(cmd, opts) {
1181
+ super(["hlen", ...cmd], opts);
1182
+ }
1183
+ };
1184
+
1185
+ // pkg/commands/hmset.ts
1186
+ var HMSetCommand = class extends Command {
1187
+ constructor([key, kv], opts) {
1188
+ super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
1189
+ }
1190
+ };
1191
+
1192
+ // pkg/commands/hscan.ts
1193
+ var HScanCommand = class extends Command {
1194
+ constructor([key, cursor, cmdOpts], opts) {
1195
+ const command = ["hscan", key, cursor];
1196
+ if (cmdOpts?.match) {
1197
+ command.push("match", cmdOpts.match);
1198
+ }
1199
+ if (typeof cmdOpts?.count === "number") {
1200
+ command.push("count", cmdOpts.count);
1201
+ }
1202
+ super(command, {
1203
+ deserialize: deserializeScanResponse,
1204
+ ...opts
1205
+ });
1206
+ }
1207
+ };
1208
+
1209
+ // pkg/commands/hset.ts
1210
+ var HSetCommand = class extends Command {
1211
+ constructor([key, kv], opts) {
1212
+ super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])], opts);
1213
+ }
1214
+ };
1215
+
1216
+ // pkg/commands/hsetex.ts
1217
+ var HSetExCommand = class extends Command {
1218
+ constructor([key, opts, kv], cmdOpts) {
1219
+ const command = ["hsetex", key];
1220
+ if (opts.conditional) {
1221
+ command.push(opts.conditional.toUpperCase());
1222
+ }
1223
+ if (opts.expiration) {
1224
+ if ("ex" in opts.expiration && typeof opts.expiration.ex === "number") {
1225
+ command.push("EX", opts.expiration.ex);
1226
+ } else if ("px" in opts.expiration && typeof opts.expiration.px === "number") {
1227
+ command.push("PX", opts.expiration.px);
1228
+ } else if ("exat" in opts.expiration && typeof opts.expiration.exat === "number") {
1229
+ command.push("EXAT", opts.expiration.exat);
1230
+ } else if ("pxat" in opts.expiration && typeof opts.expiration.pxat === "number") {
1231
+ command.push("PXAT", opts.expiration.pxat);
1232
+ } else if ("keepttl" in opts.expiration && opts.expiration.keepttl) {
1233
+ command.push("KEEPTTL");
1234
+ }
1235
+ }
1236
+ const entries = Object.entries(kv);
1237
+ command.push("FIELDS", entries.length);
1238
+ for (const [field, value] of entries) {
1239
+ command.push(field, value);
1240
+ }
1241
+ super(command, cmdOpts);
1242
+ }
1243
+ };
1244
+
1245
+ // pkg/commands/hsetnx.ts
1246
+ var HSetNXCommand = class extends Command {
1247
+ constructor(cmd, opts) {
1248
+ super(["hsetnx", ...cmd], opts);
1249
+ }
1250
+ };
1251
+
1252
+ // pkg/commands/hstrlen.ts
1253
+ var HStrLenCommand = class extends Command {
1254
+ constructor(cmd, opts) {
1255
+ super(["hstrlen", ...cmd], opts);
1256
+ }
1257
+ };
1258
+
1259
+ // pkg/commands/httl.ts
1260
+ var HTtlCommand = class extends Command {
1261
+ constructor(cmd, opts) {
1262
+ const [key, fields] = cmd;
1263
+ const fieldArray = Array.isArray(fields) ? fields : [fields];
1264
+ super(["httl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
1265
+ }
1266
+ };
1267
+
1268
+ // pkg/commands/hvals.ts
1269
+ var HValsCommand = class extends Command {
1270
+ constructor(cmd, opts) {
1271
+ super(["hvals", ...cmd], opts);
1272
+ }
1273
+ };
1274
+
1275
+ // pkg/commands/incr.ts
1276
+ var IncrCommand = class extends Command {
1277
+ constructor(cmd, opts) {
1278
+ super(["incr", ...cmd], opts);
1279
+ }
1280
+ };
1281
+
1282
+ // pkg/commands/incrby.ts
1283
+ var IncrByCommand = class extends Command {
1284
+ constructor(cmd, opts) {
1285
+ super(["incrby", ...cmd], opts);
1286
+ }
1287
+ };
1288
+
1289
+ // pkg/commands/incrbyfloat.ts
1290
+ var IncrByFloatCommand = class extends Command {
1291
+ constructor(cmd, opts) {
1292
+ super(["incrbyfloat", ...cmd], opts);
1293
+ }
1294
+ };
1295
+
1296
+ // pkg/commands/json_arrappend.ts
1297
+ var JsonArrAppendCommand = class extends Command {
1298
+ constructor(cmd, opts) {
1299
+ super(["JSON.ARRAPPEND", ...cmd], opts);
1300
+ }
1301
+ };
1302
+
1303
+ // pkg/commands/json_arrindex.ts
1304
+ var JsonArrIndexCommand = class extends Command {
1305
+ constructor(cmd, opts) {
1306
+ super(["JSON.ARRINDEX", ...cmd], opts);
1307
+ }
1308
+ };
1309
+
1310
+ // pkg/commands/json_arrinsert.ts
1311
+ var JsonArrInsertCommand = class extends Command {
1312
+ constructor(cmd, opts) {
1313
+ super(["JSON.ARRINSERT", ...cmd], opts);
1314
+ }
1315
+ };
1316
+
1317
+ // pkg/commands/json_arrlen.ts
1318
+ var JsonArrLenCommand = class extends Command {
1319
+ constructor(cmd, opts) {
1320
+ super(["JSON.ARRLEN", cmd[0], cmd[1] ?? "$"], opts);
1321
+ }
1322
+ };
1323
+
1324
+ // pkg/commands/json_arrpop.ts
1325
+ var JsonArrPopCommand = class extends Command {
1326
+ constructor(cmd, opts) {
1327
+ super(["JSON.ARRPOP", ...cmd], opts);
1328
+ }
1329
+ };
1330
+
1331
+ // pkg/commands/json_arrtrim.ts
1332
+ var JsonArrTrimCommand = class extends Command {
1333
+ constructor(cmd, opts) {
1334
+ const path = cmd[1] ?? "$";
1335
+ const start = cmd[2] ?? 0;
1336
+ const stop = cmd[3] ?? 0;
1337
+ super(["JSON.ARRTRIM", cmd[0], path, start, stop], opts);
1338
+ }
1339
+ };
1340
+
1341
+ // pkg/commands/json_clear.ts
1342
+ var JsonClearCommand = class extends Command {
1343
+ constructor(cmd, opts) {
1344
+ super(["JSON.CLEAR", ...cmd], opts);
1345
+ }
1346
+ };
1347
+
1348
+ // pkg/commands/json_del.ts
1349
+ var JsonDelCommand = class extends Command {
1350
+ constructor(cmd, opts) {
1351
+ super(["JSON.DEL", ...cmd], opts);
1352
+ }
1353
+ };
1354
+
1355
+ // pkg/commands/json_forget.ts
1356
+ var JsonForgetCommand = class extends Command {
1357
+ constructor(cmd, opts) {
1358
+ super(["JSON.FORGET", ...cmd], opts);
1359
+ }
1360
+ };
1361
+
1362
+ // pkg/commands/json_get.ts
1363
+ var JsonGetCommand = class extends Command {
1364
+ constructor(cmd, opts) {
1365
+ const command = ["JSON.GET"];
1366
+ if (typeof cmd[1] === "string") {
1367
+ command.push(...cmd);
1368
+ } else {
1369
+ command.push(cmd[0]);
1370
+ if (cmd[1]) {
1371
+ if (cmd[1].indent) {
1372
+ command.push("INDENT", cmd[1].indent);
1373
+ }
1374
+ if (cmd[1].newline) {
1375
+ command.push("NEWLINE", cmd[1].newline);
1376
+ }
1377
+ if (cmd[1].space) {
1378
+ command.push("SPACE", cmd[1].space);
1379
+ }
1380
+ }
1381
+ command.push(...cmd.slice(2));
1382
+ }
1383
+ super(command, opts);
1384
+ }
1385
+ };
1386
+
1387
+ // pkg/commands/json_merge.ts
1388
+ var JsonMergeCommand = class extends Command {
1389
+ constructor(cmd, opts) {
1390
+ const command = ["JSON.MERGE", ...cmd];
1391
+ super(command, opts);
1392
+ }
1393
+ };
1394
+
1395
+ // pkg/commands/json_mget.ts
1396
+ var JsonMGetCommand = class extends Command {
1397
+ constructor(cmd, opts) {
1398
+ super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
1399
+ }
1400
+ };
1401
+
1402
+ // pkg/commands/json_mset.ts
1403
+ var JsonMSetCommand = class extends Command {
1404
+ constructor(cmd, opts) {
1405
+ const command = ["JSON.MSET"];
1406
+ for (const c of cmd) {
1407
+ command.push(c.key, c.path, c.value);
1408
+ }
1409
+ super(command, opts);
1410
+ }
1411
+ };
1412
+
1413
+ // pkg/commands/json_numincrby.ts
1414
+ var JsonNumIncrByCommand = class extends Command {
1415
+ constructor(cmd, opts) {
1416
+ super(["JSON.NUMINCRBY", ...cmd], opts);
1417
+ }
1418
+ };
1419
+
1420
+ // pkg/commands/json_nummultby.ts
1421
+ var JsonNumMultByCommand = class extends Command {
1422
+ constructor(cmd, opts) {
1423
+ super(["JSON.NUMMULTBY", ...cmd], opts);
1424
+ }
1425
+ };
1426
+
1427
+ // pkg/commands/json_objkeys.ts
1428
+ var JsonObjKeysCommand = class extends Command {
1429
+ constructor(cmd, opts) {
1430
+ super(["JSON.OBJKEYS", ...cmd], opts);
1431
+ }
1432
+ };
1433
+
1434
+ // pkg/commands/json_objlen.ts
1435
+ var JsonObjLenCommand = class extends Command {
1436
+ constructor(cmd, opts) {
1437
+ super(["JSON.OBJLEN", ...cmd], opts);
1438
+ }
1439
+ };
1440
+
1441
+ // pkg/commands/json_resp.ts
1442
+ var JsonRespCommand = class extends Command {
1443
+ constructor(cmd, opts) {
1444
+ super(["JSON.RESP", ...cmd], opts);
1445
+ }
1446
+ };
1447
+
1448
+ // pkg/commands/json_set.ts
1449
+ var JsonSetCommand = class extends Command {
1450
+ constructor(cmd, opts) {
1451
+ const command = ["JSON.SET", cmd[0], cmd[1], cmd[2]];
1452
+ if (cmd[3]) {
1453
+ if (cmd[3].nx) {
1454
+ command.push("NX");
1455
+ } else if (cmd[3].xx) {
1456
+ command.push("XX");
1457
+ }
1458
+ }
1459
+ super(command, opts);
1460
+ }
1461
+ };
1462
+
1463
+ // pkg/commands/json_strappend.ts
1464
+ var JsonStrAppendCommand = class extends Command {
1465
+ constructor(cmd, opts) {
1466
+ super(["JSON.STRAPPEND", ...cmd], opts);
1467
+ }
1468
+ };
1469
+
1470
+ // pkg/commands/json_strlen.ts
1471
+ var JsonStrLenCommand = class extends Command {
1472
+ constructor(cmd, opts) {
1473
+ super(["JSON.STRLEN", ...cmd], opts);
1474
+ }
1475
+ };
1476
+
1477
+ // pkg/commands/json_toggle.ts
1478
+ var JsonToggleCommand = class extends Command {
1479
+ constructor(cmd, opts) {
1480
+ super(["JSON.TOGGLE", ...cmd], opts);
1481
+ }
1482
+ };
1483
+
1484
+ // pkg/commands/json_type.ts
1485
+ var JsonTypeCommand = class extends Command {
1486
+ constructor(cmd, opts) {
1487
+ super(["JSON.TYPE", ...cmd], opts);
1488
+ }
1489
+ };
1490
+
1491
+ // pkg/commands/keys.ts
1492
+ var KeysCommand = class extends Command {
1493
+ constructor(cmd, opts) {
1494
+ super(["keys", ...cmd], opts);
1495
+ }
1496
+ };
1497
+
1498
+ // pkg/commands/lindex.ts
1499
+ var LIndexCommand = class extends Command {
1500
+ constructor(cmd, opts) {
1501
+ super(["lindex", ...cmd], opts);
1502
+ }
1503
+ };
1504
+
1505
+ // pkg/commands/linsert.ts
1506
+ var LInsertCommand = class extends Command {
1507
+ constructor(cmd, opts) {
1508
+ super(["linsert", ...cmd], opts);
1509
+ }
1510
+ };
1511
+
1512
+ // pkg/commands/llen.ts
1513
+ var LLenCommand = class extends Command {
1514
+ constructor(cmd, opts) {
1515
+ super(["llen", ...cmd], opts);
1516
+ }
1517
+ };
1518
+
1519
+ // pkg/commands/lmove.ts
1520
+ var LMoveCommand = class extends Command {
1521
+ constructor(cmd, opts) {
1522
+ super(["lmove", ...cmd], opts);
1523
+ }
1524
+ };
1525
+
1526
+ // pkg/commands/lmpop.ts
1527
+ var LmPopCommand = class extends Command {
1528
+ constructor(cmd, opts) {
1529
+ const [numkeys, keys, direction, count] = cmd;
1530
+ super(["LMPOP", numkeys, ...keys, direction, ...count ? ["COUNT", count] : []], opts);
1531
+ }
1532
+ };
1533
+
1534
+ // pkg/commands/lpop.ts
1535
+ var LPopCommand = class extends Command {
1536
+ constructor(cmd, opts) {
1537
+ super(["lpop", ...cmd], opts);
1538
+ }
1539
+ };
1540
+
1541
+ // pkg/commands/lpos.ts
1542
+ var LPosCommand = class extends Command {
1543
+ constructor(cmd, opts) {
1544
+ const args = ["lpos", cmd[0], cmd[1]];
1545
+ if (typeof cmd[2]?.rank === "number") {
1546
+ args.push("rank", cmd[2].rank);
1547
+ }
1548
+ if (typeof cmd[2]?.count === "number") {
1549
+ args.push("count", cmd[2].count);
1550
+ }
1551
+ if (typeof cmd[2]?.maxLen === "number") {
1552
+ args.push("maxLen", cmd[2].maxLen);
1553
+ }
1554
+ super(args, opts);
1555
+ }
1556
+ };
1557
+
1558
+ // pkg/commands/lpush.ts
1559
+ var LPushCommand = class extends Command {
1560
+ constructor(cmd, opts) {
1561
+ super(["lpush", ...cmd], opts);
1562
+ }
1563
+ };
1564
+
1565
+ // pkg/commands/lpushx.ts
1566
+ var LPushXCommand = class extends Command {
1567
+ constructor(cmd, opts) {
1568
+ super(["lpushx", ...cmd], opts);
1569
+ }
1570
+ };
1571
+
1572
+ // pkg/commands/lrange.ts
1573
+ var LRangeCommand = class extends Command {
1574
+ constructor(cmd, opts) {
1575
+ super(["lrange", ...cmd], opts);
1576
+ }
1577
+ };
1578
+
1579
+ // pkg/commands/lrem.ts
1580
+ var LRemCommand = class extends Command {
1581
+ constructor(cmd, opts) {
1582
+ super(["lrem", ...cmd], opts);
1583
+ }
1584
+ };
1585
+
1586
+ // pkg/commands/lset.ts
1587
+ var LSetCommand = class extends Command {
1588
+ constructor(cmd, opts) {
1589
+ super(["lset", ...cmd], opts);
1590
+ }
1591
+ };
1592
+
1593
+ // pkg/commands/ltrim.ts
1594
+ var LTrimCommand = class extends Command {
1595
+ constructor(cmd, opts) {
1596
+ super(["ltrim", ...cmd], opts);
1597
+ }
1598
+ };
1599
+
1600
+ // pkg/commands/mget.ts
1601
+ var MGetCommand = class extends Command {
1602
+ constructor(cmd, opts) {
1603
+ const keys = Array.isArray(cmd[0]) ? cmd[0] : cmd;
1604
+ super(["mget", ...keys], opts);
1605
+ }
1606
+ };
1607
+
1608
+ // pkg/commands/mset.ts
1609
+ var MSetCommand = class extends Command {
1610
+ constructor([kv], opts) {
1611
+ super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])], opts);
1612
+ }
1613
+ };
1614
+
1615
+ // pkg/commands/msetnx.ts
1616
+ var MSetNXCommand = class extends Command {
1617
+ constructor([kv], opts) {
1618
+ super(["msetnx", ...Object.entries(kv).flat()], opts);
1619
+ }
1620
+ };
1621
+
1622
+ // pkg/commands/persist.ts
1623
+ var PersistCommand = class extends Command {
1624
+ constructor(cmd, opts) {
1625
+ super(["persist", ...cmd], opts);
1626
+ }
1627
+ };
1628
+
1629
+ // pkg/commands/pexpire.ts
1630
+ var PExpireCommand = class extends Command {
1631
+ constructor(cmd, opts) {
1632
+ super(["pexpire", ...cmd], opts);
1633
+ }
1634
+ };
1635
+
1636
+ // pkg/commands/pexpireat.ts
1637
+ var PExpireAtCommand = class extends Command {
1638
+ constructor(cmd, opts) {
1639
+ super(["pexpireat", ...cmd], opts);
1640
+ }
1641
+ };
1642
+
1643
+ // pkg/commands/pfadd.ts
1644
+ var PfAddCommand = class extends Command {
1645
+ constructor(cmd, opts) {
1646
+ super(["pfadd", ...cmd], opts);
1647
+ }
1648
+ };
1649
+
1650
+ // pkg/commands/pfcount.ts
1651
+ var PfCountCommand = class extends Command {
1652
+ constructor(cmd, opts) {
1653
+ super(["pfcount", ...cmd], opts);
1654
+ }
1655
+ };
1656
+
1657
+ // pkg/commands/pfmerge.ts
1658
+ var PfMergeCommand = class extends Command {
1659
+ constructor(cmd, opts) {
1660
+ super(["pfmerge", ...cmd], opts);
1661
+ }
1662
+ };
1663
+
1664
+ // pkg/commands/ping.ts
1665
+ var PingCommand = class extends Command {
1666
+ constructor(cmd, opts) {
1667
+ const command = ["ping"];
1668
+ if (cmd?.[0] !== void 0) {
1669
+ command.push(cmd[0]);
1670
+ }
1671
+ super(command, opts);
1672
+ }
1673
+ };
1674
+
1675
+ // pkg/commands/psetex.ts
1676
+ var PSetEXCommand = class extends Command {
1677
+ constructor(cmd, opts) {
1678
+ super(["psetex", ...cmd], opts);
1679
+ }
1680
+ };
1681
+
1682
+ // pkg/commands/pttl.ts
1683
+ var PTtlCommand = class extends Command {
1684
+ constructor(cmd, opts) {
1685
+ super(["pttl", ...cmd], opts);
1686
+ }
1687
+ };
1688
+
1689
+ // pkg/commands/publish.ts
1690
+ var PublishCommand = class extends Command {
1691
+ constructor(cmd, opts) {
1692
+ super(["publish", ...cmd], opts);
1693
+ }
1694
+ };
1695
+
1696
+ // pkg/commands/randomkey.ts
1697
+ var RandomKeyCommand = class extends Command {
1698
+ constructor(opts) {
1699
+ super(["randomkey"], opts);
1700
+ }
1701
+ };
1702
+
1703
+ // pkg/commands/rename.ts
1704
+ var RenameCommand = class extends Command {
1705
+ constructor(cmd, opts) {
1706
+ super(["rename", ...cmd], opts);
1707
+ }
1708
+ };
1709
+
1710
+ // pkg/commands/renamenx.ts
1711
+ var RenameNXCommand = class extends Command {
1712
+ constructor(cmd, opts) {
1713
+ super(["renamenx", ...cmd], opts);
1714
+ }
1715
+ };
1716
+
1717
+ // pkg/commands/rpop.ts
1718
+ var RPopCommand = class extends Command {
1719
+ constructor(cmd, opts) {
1720
+ super(["rpop", ...cmd], opts);
1721
+ }
1722
+ };
1723
+
1724
+ // pkg/commands/rpush.ts
1725
+ var RPushCommand = class extends Command {
1726
+ constructor(cmd, opts) {
1727
+ super(["rpush", ...cmd], opts);
1728
+ }
1729
+ };
1730
+
1731
+ // pkg/commands/rpushx.ts
1732
+ var RPushXCommand = class extends Command {
1733
+ constructor(cmd, opts) {
1734
+ super(["rpushx", ...cmd], opts);
1735
+ }
1736
+ };
1737
+
1738
+ // pkg/commands/sadd.ts
1739
+ var SAddCommand = class extends Command {
1740
+ constructor(cmd, opts) {
1741
+ super(["sadd", ...cmd], opts);
1742
+ }
1743
+ };
1744
+
1745
+ // pkg/commands/scan.ts
1746
+ var ScanCommand = class extends Command {
1747
+ constructor([cursor, opts], cmdOpts) {
1748
+ const command = ["scan", cursor];
1749
+ if (opts?.match) {
1750
+ command.push("match", opts.match);
1751
+ }
1752
+ if (typeof opts?.count === "number") {
1753
+ command.push("count", opts.count);
1754
+ }
1755
+ if (opts && "withType" in opts && opts.withType === true) {
1756
+ command.push("withtype");
1757
+ } else if (opts && "type" in opts && opts.type && opts.type.length > 0) {
1758
+ command.push("type", opts.type);
1759
+ }
1760
+ super(command, {
1761
+ // @ts-expect-error ignore types here
1762
+ deserialize: opts?.withType ? deserializeScanWithTypesResponse : deserializeScanResponse,
1763
+ ...cmdOpts
1764
+ });
1765
+ }
1766
+ };
1767
+
1768
+ // pkg/commands/scard.ts
1769
+ var SCardCommand = class extends Command {
1770
+ constructor(cmd, opts) {
1771
+ super(["scard", ...cmd], opts);
1772
+ }
1773
+ };
1774
+
1775
+ // pkg/commands/script_exists.ts
1776
+ var ScriptExistsCommand = class extends Command {
1777
+ constructor(hashes, opts) {
1778
+ super(["script", "exists", ...hashes], {
1779
+ deserialize: (result) => result,
1780
+ ...opts
1781
+ });
1782
+ }
1783
+ };
1784
+
1785
+ // pkg/commands/script_flush.ts
1786
+ var ScriptFlushCommand = class extends Command {
1787
+ constructor([opts], cmdOpts) {
1788
+ const cmd = ["script", "flush"];
1789
+ if (opts?.sync) {
1790
+ cmd.push("sync");
1791
+ } else if (opts?.async) {
1792
+ cmd.push("async");
1793
+ }
1794
+ super(cmd, cmdOpts);
1795
+ }
1796
+ };
1797
+
1798
+ // pkg/commands/script_load.ts
1799
+ var ScriptLoadCommand = class extends Command {
1800
+ constructor(args, opts) {
1801
+ super(["script", "load", ...args], opts);
1802
+ }
1803
+ };
1804
+
1805
+ // pkg/commands/sdiff.ts
1806
+ var SDiffCommand = class extends Command {
1807
+ constructor(cmd, opts) {
1808
+ super(["sdiff", ...cmd], opts);
1809
+ }
1810
+ };
1811
+
1812
+ // pkg/commands/sdiffstore.ts
1813
+ var SDiffStoreCommand = class extends Command {
1814
+ constructor(cmd, opts) {
1815
+ super(["sdiffstore", ...cmd], opts);
1816
+ }
1817
+ };
1818
+
1819
+ // pkg/commands/set.ts
1820
+ var SetCommand = class extends Command {
1821
+ constructor([key, value, opts], cmdOpts) {
1822
+ const command = ["set", key, value];
1823
+ if (opts) {
1824
+ if ("nx" in opts && opts.nx) {
1825
+ command.push("nx");
1826
+ } else if ("xx" in opts && opts.xx) {
1827
+ command.push("xx");
1828
+ }
1829
+ if ("get" in opts && opts.get) {
1830
+ command.push("get");
1831
+ }
1832
+ if ("ex" in opts && typeof opts.ex === "number") {
1833
+ command.push("ex", opts.ex);
1834
+ } else if ("px" in opts && typeof opts.px === "number") {
1835
+ command.push("px", opts.px);
1836
+ } else if ("exat" in opts && typeof opts.exat === "number") {
1837
+ command.push("exat", opts.exat);
1838
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
1839
+ command.push("pxat", opts.pxat);
1840
+ } else if ("keepTtl" in opts && opts.keepTtl) {
1841
+ command.push("keepTtl");
1842
+ }
1843
+ }
1844
+ super(command, cmdOpts);
1845
+ }
1846
+ };
1847
+
1848
+ // pkg/commands/setbit.ts
1849
+ var SetBitCommand = class extends Command {
1850
+ constructor(cmd, opts) {
1851
+ super(["setbit", ...cmd], opts);
1852
+ }
1853
+ };
1854
+
1855
+ // pkg/commands/setex.ts
1856
+ var SetExCommand = class extends Command {
1857
+ constructor(cmd, opts) {
1858
+ super(["setex", ...cmd], opts);
1859
+ }
1860
+ };
1861
+
1862
+ // pkg/commands/setnx.ts
1863
+ var SetNxCommand = class extends Command {
1864
+ constructor(cmd, opts) {
1865
+ super(["setnx", ...cmd], opts);
1866
+ }
1867
+ };
1868
+
1869
+ // pkg/commands/setrange.ts
1870
+ var SetRangeCommand = class extends Command {
1871
+ constructor(cmd, opts) {
1872
+ super(["setrange", ...cmd], opts);
1873
+ }
1874
+ };
1875
+
1876
+ // pkg/commands/sinter.ts
1877
+ var SInterCommand = class extends Command {
1878
+ constructor(cmd, opts) {
1879
+ super(["sinter", ...cmd], opts);
1880
+ }
1881
+ };
1882
+
1883
+ // pkg/commands/sinterstore.ts
1884
+ var SInterStoreCommand = class extends Command {
1885
+ constructor(cmd, opts) {
1886
+ super(["sinterstore", ...cmd], opts);
1887
+ }
1888
+ };
1889
+
1890
+ // pkg/commands/sismember.ts
1891
+ var SIsMemberCommand = class extends Command {
1892
+ constructor(cmd, opts) {
1893
+ super(["sismember", ...cmd], opts);
1894
+ }
1895
+ };
1896
+
1897
+ // pkg/commands/smembers.ts
1898
+ var SMembersCommand = class extends Command {
1899
+ constructor(cmd, opts) {
1900
+ super(["smembers", ...cmd], opts);
1901
+ }
1902
+ };
1903
+
1904
+ // pkg/commands/smismember.ts
1905
+ var SMIsMemberCommand = class extends Command {
1906
+ constructor(cmd, opts) {
1907
+ super(["smismember", cmd[0], ...cmd[1]], opts);
1908
+ }
1909
+ };
1910
+
1911
+ // pkg/commands/smove.ts
1912
+ var SMoveCommand = class extends Command {
1913
+ constructor(cmd, opts) {
1914
+ super(["smove", ...cmd], opts);
1915
+ }
1916
+ };
1917
+
1918
+ // pkg/commands/spop.ts
1919
+ var SPopCommand = class extends Command {
1920
+ constructor([key, count], opts) {
1921
+ const command = ["spop", key];
1922
+ if (typeof count === "number") {
1923
+ command.push(count);
1924
+ }
1925
+ super(command, opts);
1926
+ }
1927
+ };
1928
+
1929
+ // pkg/commands/srandmember.ts
1930
+ var SRandMemberCommand = class extends Command {
1931
+ constructor([key, count], opts) {
1932
+ const command = ["srandmember", key];
1933
+ if (typeof count === "number") {
1934
+ command.push(count);
1935
+ }
1936
+ super(command, opts);
1937
+ }
1938
+ };
1939
+
1940
+ // pkg/commands/srem.ts
1941
+ var SRemCommand = class extends Command {
1942
+ constructor(cmd, opts) {
1943
+ super(["srem", ...cmd], opts);
1944
+ }
1945
+ };
1946
+
1947
+ // pkg/commands/sscan.ts
1948
+ var SScanCommand = class extends Command {
1949
+ constructor([key, cursor, opts], cmdOpts) {
1950
+ const command = ["sscan", key, cursor];
1951
+ if (opts?.match) {
1952
+ command.push("match", opts.match);
1953
+ }
1954
+ if (typeof opts?.count === "number") {
1955
+ command.push("count", opts.count);
1956
+ }
1957
+ super(command, {
1958
+ deserialize: deserializeScanResponse,
1959
+ ...cmdOpts
1960
+ });
1961
+ }
1962
+ };
1963
+
1964
+ // pkg/commands/strlen.ts
1965
+ var StrLenCommand = class extends Command {
1966
+ constructor(cmd, opts) {
1967
+ super(["strlen", ...cmd], opts);
1968
+ }
1969
+ };
1970
+
1971
+ // pkg/commands/sunion.ts
1972
+ var SUnionCommand = class extends Command {
1973
+ constructor(cmd, opts) {
1974
+ super(["sunion", ...cmd], opts);
1975
+ }
1976
+ };
1977
+
1978
+ // pkg/commands/sunionstore.ts
1979
+ var SUnionStoreCommand = class extends Command {
1980
+ constructor(cmd, opts) {
1981
+ super(["sunionstore", ...cmd], opts);
1982
+ }
1983
+ };
1984
+
1985
+ // pkg/commands/time.ts
1986
+ var TimeCommand = class extends Command {
1987
+ constructor(opts) {
1988
+ super(["time"], opts);
1989
+ }
1990
+ };
1991
+
1992
+ // pkg/commands/touch.ts
1993
+ var TouchCommand = class extends Command {
1994
+ constructor(cmd, opts) {
1995
+ super(["touch", ...cmd], opts);
1996
+ }
1997
+ };
1998
+
1999
+ // pkg/commands/ttl.ts
2000
+ var TtlCommand = class extends Command {
2001
+ constructor(cmd, opts) {
2002
+ super(["ttl", ...cmd], opts);
2003
+ }
2004
+ };
2005
+
2006
+ // pkg/commands/type.ts
2007
+ var TypeCommand = class extends Command {
2008
+ constructor(cmd, opts) {
2009
+ super(["type", ...cmd], opts);
2010
+ }
2011
+ };
2012
+
2013
+ // pkg/commands/unlink.ts
2014
+ var UnlinkCommand = class extends Command {
2015
+ constructor(cmd, opts) {
2016
+ super(["unlink", ...cmd], opts);
2017
+ }
2018
+ };
2019
+
2020
+ // pkg/commands/xack.ts
2021
+ var XAckCommand = class extends Command {
2022
+ constructor([key, group, id], opts) {
2023
+ const ids = Array.isArray(id) ? [...id] : [id];
2024
+ super(["XACK", key, group, ...ids], opts);
2025
+ }
2026
+ };
2027
+
2028
+ // pkg/commands/xackdel.ts
2029
+ var XAckDelCommand = class extends Command {
2030
+ constructor([key, group, opts, ...ids], cmdOpts) {
2031
+ const command = ["XACKDEL", key, group];
2032
+ command.push(opts.toUpperCase());
2033
+ command.push("IDS", ids.length, ...ids);
2034
+ super(command, cmdOpts);
2035
+ }
2036
+ };
2037
+
2038
+ // pkg/commands/xadd.ts
2039
+ var XAddCommand = class extends Command {
2040
+ constructor([key, id, entries, opts], commandOptions) {
2041
+ const command = ["XADD", key];
2042
+ if (opts) {
2043
+ if (opts.nomkStream) {
2044
+ command.push("NOMKSTREAM");
2045
+ }
2046
+ if (opts.trim) {
2047
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
2048
+ if (opts.trim.limit !== void 0) {
2049
+ command.push("LIMIT", opts.trim.limit);
2050
+ }
2051
+ }
2052
+ }
2053
+ command.push(id);
2054
+ for (const [k, v] of Object.entries(entries)) {
2055
+ command.push(k, v);
2056
+ }
2057
+ super(command, commandOptions);
2058
+ }
2059
+ };
2060
+
2061
+ // pkg/commands/xautoclaim.ts
2062
+ var XAutoClaim = class extends Command {
2063
+ constructor([key, group, consumer, minIdleTime, start, options], opts) {
2064
+ const commands = [];
2065
+ if (options?.count) {
2066
+ commands.push("COUNT", options.count);
2067
+ }
2068
+ if (options?.justId) {
2069
+ commands.push("JUSTID");
2070
+ }
2071
+ super(["XAUTOCLAIM", key, group, consumer, minIdleTime, start, ...commands], opts);
2072
+ }
2073
+ };
2074
+
2075
+ // pkg/commands/xclaim.ts
2076
+ var XClaimCommand = class extends Command {
2077
+ constructor([key, group, consumer, minIdleTime, id, options], opts) {
2078
+ const ids = Array.isArray(id) ? [...id] : [id];
2079
+ const commands = [];
2080
+ if (options?.idleMS) {
2081
+ commands.push("IDLE", options.idleMS);
2082
+ }
2083
+ if (options?.idleMS) {
2084
+ commands.push("TIME", options.timeMS);
2085
+ }
2086
+ if (options?.retryCount) {
2087
+ commands.push("RETRYCOUNT", options.retryCount);
2088
+ }
2089
+ if (options?.force) {
2090
+ commands.push("FORCE");
2091
+ }
2092
+ if (options?.justId) {
2093
+ commands.push("JUSTID");
2094
+ }
2095
+ if (options?.lastId) {
2096
+ commands.push("LASTID", options.lastId);
2097
+ }
2098
+ super(["XCLAIM", key, group, consumer, minIdleTime, ...ids, ...commands], opts);
2099
+ }
2100
+ };
2101
+
2102
+ // pkg/commands/xdel.ts
2103
+ var XDelCommand = class extends Command {
2104
+ constructor([key, ids], opts) {
2105
+ const cmds = Array.isArray(ids) ? [...ids] : [ids];
2106
+ super(["XDEL", key, ...cmds], opts);
2107
+ }
2108
+ };
2109
+
2110
+ // pkg/commands/xdelex.ts
2111
+ var XDelExCommand = class extends Command {
2112
+ constructor([key, opts, ...ids], cmdOpts) {
2113
+ const command = ["XDELEX", key];
2114
+ if (opts) {
2115
+ command.push(opts.toUpperCase());
2116
+ }
2117
+ command.push("IDS", ids.length, ...ids);
2118
+ super(command, cmdOpts);
2119
+ }
2120
+ };
2121
+
2122
+ // pkg/commands/xgroup.ts
2123
+ var XGroupCommand = class extends Command {
2124
+ constructor([key, opts], commandOptions) {
2125
+ const command = ["XGROUP"];
2126
+ switch (opts.type) {
2127
+ case "CREATE": {
2128
+ command.push("CREATE", key, opts.group, opts.id);
2129
+ if (opts.options) {
2130
+ if (opts.options.MKSTREAM) {
2131
+ command.push("MKSTREAM");
2132
+ }
2133
+ if (opts.options.ENTRIESREAD !== void 0) {
2134
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
2135
+ }
2136
+ }
2137
+ break;
2138
+ }
2139
+ case "CREATECONSUMER": {
2140
+ command.push("CREATECONSUMER", key, opts.group, opts.consumer);
2141
+ break;
2142
+ }
2143
+ case "DELCONSUMER": {
2144
+ command.push("DELCONSUMER", key, opts.group, opts.consumer);
2145
+ break;
2146
+ }
2147
+ case "DESTROY": {
2148
+ command.push("DESTROY", key, opts.group);
2149
+ break;
2150
+ }
2151
+ case "SETID": {
2152
+ command.push("SETID", key, opts.group, opts.id);
2153
+ if (opts.options?.ENTRIESREAD !== void 0) {
2154
+ command.push("ENTRIESREAD", opts.options.ENTRIESREAD.toString());
2155
+ }
2156
+ break;
2157
+ }
2158
+ default: {
2159
+ throw new Error("Invalid XGROUP");
2160
+ }
2161
+ }
2162
+ super(command, commandOptions);
2163
+ }
2164
+ };
2165
+
2166
+ // pkg/commands/xinfo.ts
2167
+ var XInfoCommand = class extends Command {
2168
+ constructor([key, options], opts) {
2169
+ const cmds = [];
2170
+ if (options.type === "CONSUMERS") {
2171
+ cmds.push("CONSUMERS", key, options.group);
2172
+ } else {
2173
+ cmds.push("GROUPS", key);
2174
+ }
2175
+ super(["XINFO", ...cmds], opts);
2176
+ }
2177
+ };
2178
+
2179
+ // pkg/commands/xlen.ts
2180
+ var XLenCommand = class extends Command {
2181
+ constructor(cmd, opts) {
2182
+ super(["XLEN", ...cmd], opts);
2183
+ }
2184
+ };
2185
+
2186
+ // pkg/commands/xpending.ts
2187
+ var XPendingCommand = class extends Command {
2188
+ constructor([key, group, start, end, count, options], opts) {
2189
+ const consumers = options?.consumer === void 0 ? [] : Array.isArray(options.consumer) ? [...options.consumer] : [options.consumer];
2190
+ super(
2191
+ [
2192
+ "XPENDING",
2193
+ key,
2194
+ group,
2195
+ ...options?.idleTime ? ["IDLE", options.idleTime] : [],
2196
+ start,
2197
+ end,
2198
+ count,
2199
+ ...consumers
2200
+ ],
2201
+ opts
2202
+ );
2203
+ }
2204
+ };
2205
+
2206
+ // pkg/commands/xrange.ts
2207
+ function deserialize6(result) {
2208
+ const obj = {};
2209
+ for (const e of result) {
2210
+ for (let i = 0; i < e.length; i += 2) {
2211
+ const streamId = e[i];
2212
+ const entries = e[i + 1];
2213
+ if (!(streamId in obj)) {
2214
+ obj[streamId] = {};
2215
+ }
2216
+ for (let j = 0; j < entries.length; j += 2) {
2217
+ const field = entries[j];
2218
+ const value = entries[j + 1];
2219
+ try {
2220
+ obj[streamId][field] = JSON.parse(value);
2221
+ } catch {
2222
+ obj[streamId][field] = value;
2223
+ }
2224
+ }
2225
+ }
2226
+ }
2227
+ return obj;
2228
+ }
2229
+ var XRangeCommand = class extends Command {
2230
+ constructor([key, start, end, count], opts) {
2231
+ const command = ["XRANGE", key, start, end];
2232
+ if (typeof count === "number") {
2233
+ command.push("COUNT", count);
2234
+ }
2235
+ super(command, {
2236
+ deserialize: (result) => deserialize6(result),
2237
+ ...opts
2238
+ });
2239
+ }
2240
+ };
2241
+
2242
+ // pkg/commands/xread.ts
2243
+ var UNBALANCED_XREAD_ERR = "ERR Unbalanced XREAD list of streams: for each stream key an ID or '$' must be specified";
2244
+ var XReadCommand = class extends Command {
2245
+ constructor([key, id, options], opts) {
2246
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
2247
+ throw new Error(UNBALANCED_XREAD_ERR);
2248
+ }
2249
+ const commands = [];
2250
+ if (typeof options?.count === "number") {
2251
+ commands.push("COUNT", options.count);
2252
+ }
2253
+ if (typeof options?.blockMS === "number") {
2254
+ commands.push("BLOCK", options.blockMS);
2255
+ }
2256
+ commands.push(
2257
+ "STREAMS",
2258
+ ...Array.isArray(key) ? [...key] : [key],
2259
+ ...Array.isArray(id) ? [...id] : [id]
2260
+ );
2261
+ super(["XREAD", ...commands], opts);
2262
+ }
2263
+ };
2264
+
2265
+ // pkg/commands/xreadgroup.ts
2266
+ var UNBALANCED_XREADGROUP_ERR = "ERR Unbalanced XREADGROUP list of streams: for each stream key an ID or '$' must be specified";
2267
+ var XReadGroupCommand = class extends Command {
2268
+ constructor([group, consumer, key, id, options], opts) {
2269
+ if (Array.isArray(key) && Array.isArray(id) && key.length !== id.length) {
2270
+ throw new Error(UNBALANCED_XREADGROUP_ERR);
2271
+ }
2272
+ const commands = [];
2273
+ if (typeof options?.count === "number") {
2274
+ commands.push("COUNT", options.count);
2275
+ }
2276
+ if (typeof options?.blockMS === "number") {
2277
+ commands.push("BLOCK", options.blockMS);
2278
+ }
2279
+ if (typeof options?.NOACK === "boolean" && options.NOACK) {
2280
+ commands.push("NOACK");
2281
+ }
2282
+ commands.push(
2283
+ "STREAMS",
2284
+ ...Array.isArray(key) ? [...key] : [key],
2285
+ ...Array.isArray(id) ? [...id] : [id]
2286
+ );
2287
+ super(["XREADGROUP", "GROUP", group, consumer, ...commands], opts);
2288
+ }
2289
+ };
2290
+
2291
+ // pkg/commands/xrevrange.ts
2292
+ var XRevRangeCommand = class extends Command {
2293
+ constructor([key, end, start, count], opts) {
2294
+ const command = ["XREVRANGE", key, end, start];
2295
+ if (typeof count === "number") {
2296
+ command.push("COUNT", count);
2297
+ }
2298
+ super(command, {
2299
+ deserialize: (result) => deserialize7(result),
2300
+ ...opts
2301
+ });
2302
+ }
2303
+ };
2304
+ function deserialize7(result) {
2305
+ const obj = {};
2306
+ for (const e of result) {
2307
+ for (let i = 0; i < e.length; i += 2) {
2308
+ const streamId = e[i];
2309
+ const entries = e[i + 1];
2310
+ if (!(streamId in obj)) {
2311
+ obj[streamId] = {};
2312
+ }
2313
+ for (let j = 0; j < entries.length; j += 2) {
2314
+ const field = entries[j];
2315
+ const value = entries[j + 1];
2316
+ try {
2317
+ obj[streamId][field] = JSON.parse(value);
2318
+ } catch {
2319
+ obj[streamId][field] = value;
2320
+ }
2321
+ }
2322
+ }
2323
+ }
2324
+ return obj;
2325
+ }
2326
+
2327
+ // pkg/commands/xtrim.ts
2328
+ var XTrimCommand = class extends Command {
2329
+ constructor([key, options], opts) {
2330
+ const { limit, strategy, threshold, exactness = "~" } = options;
2331
+ super(["XTRIM", key, strategy, exactness, threshold, ...limit ? ["LIMIT", limit] : []], opts);
2332
+ }
2333
+ };
2334
+
2335
+ // pkg/commands/zadd.ts
2336
+ var ZAddCommand = class extends Command {
2337
+ constructor([key, arg1, ...arg2], opts) {
2338
+ const command = ["zadd", key];
2339
+ if ("nx" in arg1 && arg1.nx) {
2340
+ command.push("nx");
2341
+ } else if ("xx" in arg1 && arg1.xx) {
2342
+ command.push("xx");
2343
+ }
2344
+ if ("ch" in arg1 && arg1.ch) {
2345
+ command.push("ch");
2346
+ }
2347
+ if ("incr" in arg1 && arg1.incr) {
2348
+ command.push("incr");
2349
+ }
2350
+ if ("lt" in arg1 && arg1.lt) {
2351
+ command.push("lt");
2352
+ } else if ("gt" in arg1 && arg1.gt) {
2353
+ command.push("gt");
2354
+ }
2355
+ if ("score" in arg1 && "member" in arg1) {
2356
+ command.push(arg1.score, arg1.member);
2357
+ }
2358
+ command.push(...arg2.flatMap(({ score, member }) => [score, member]));
2359
+ super(command, opts);
2360
+ }
2361
+ };
2362
+
2363
+ // pkg/commands/zcard.ts
2364
+ var ZCardCommand = class extends Command {
2365
+ constructor(cmd, opts) {
2366
+ super(["zcard", ...cmd], opts);
2367
+ }
2368
+ };
2369
+
2370
+ // pkg/commands/zcount.ts
2371
+ var ZCountCommand = class extends Command {
2372
+ constructor(cmd, opts) {
2373
+ super(["zcount", ...cmd], opts);
2374
+ }
2375
+ };
2376
+
2377
+ // pkg/commands/zincrby.ts
2378
+ var ZIncrByCommand = class extends Command {
2379
+ constructor(cmd, opts) {
2380
+ super(["zincrby", ...cmd], opts);
2381
+ }
2382
+ };
2383
+
2384
+ // pkg/commands/zinterstore.ts
2385
+ var ZInterStoreCommand = class extends Command {
2386
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2387
+ const command = ["zinterstore", destination, numKeys];
2388
+ if (Array.isArray(keyOrKeys)) {
2389
+ command.push(...keyOrKeys);
2390
+ } else {
2391
+ command.push(keyOrKeys);
2392
+ }
2393
+ if (opts) {
2394
+ if ("weights" in opts && opts.weights) {
2395
+ command.push("weights", ...opts.weights);
2396
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2397
+ command.push("weights", opts.weight);
2398
+ }
2399
+ if ("aggregate" in opts) {
2400
+ command.push("aggregate", opts.aggregate);
2401
+ }
2402
+ }
2403
+ super(command, cmdOpts);
2404
+ }
2405
+ };
2406
+
2407
+ // pkg/commands/zlexcount.ts
2408
+ var ZLexCountCommand = class extends Command {
2409
+ constructor(cmd, opts) {
2410
+ super(["zlexcount", ...cmd], opts);
2411
+ }
2412
+ };
2413
+
2414
+ // pkg/commands/zpopmax.ts
2415
+ var ZPopMaxCommand = class extends Command {
2416
+ constructor([key, count], opts) {
2417
+ const command = ["zpopmax", key];
2418
+ if (typeof count === "number") {
2419
+ command.push(count);
2420
+ }
2421
+ super(command, opts);
2422
+ }
2423
+ };
2424
+
2425
+ // pkg/commands/zpopmin.ts
2426
+ var ZPopMinCommand = class extends Command {
2427
+ constructor([key, count], opts) {
2428
+ const command = ["zpopmin", key];
2429
+ if (typeof count === "number") {
2430
+ command.push(count);
2431
+ }
2432
+ super(command, opts);
2433
+ }
2434
+ };
2435
+
2436
+ // pkg/commands/zrange.ts
2437
+ var ZRangeCommand = class extends Command {
2438
+ constructor([key, min, max, opts], cmdOpts) {
2439
+ const command = ["zrange", key, min, max];
2440
+ if (opts?.byScore) {
2441
+ command.push("byscore");
2442
+ }
2443
+ if (opts?.byLex) {
2444
+ command.push("bylex");
2445
+ }
2446
+ if (opts?.rev) {
2447
+ command.push("rev");
2448
+ }
2449
+ if (opts?.count !== void 0 && opts.offset !== void 0) {
2450
+ command.push("limit", opts.offset, opts.count);
2451
+ }
2452
+ if (opts?.withScores) {
2453
+ command.push("withscores");
2454
+ }
2455
+ super(command, cmdOpts);
2456
+ }
2457
+ };
2458
+
2459
+ // pkg/commands/zrank.ts
2460
+ var ZRankCommand = class extends Command {
2461
+ constructor(cmd, opts) {
2462
+ super(["zrank", ...cmd], opts);
2463
+ }
2464
+ };
2465
+
2466
+ // pkg/commands/zrem.ts
2467
+ var ZRemCommand = class extends Command {
2468
+ constructor(cmd, opts) {
2469
+ super(["zrem", ...cmd], opts);
2470
+ }
2471
+ };
2472
+
2473
+ // pkg/commands/zremrangebylex.ts
2474
+ var ZRemRangeByLexCommand = class extends Command {
2475
+ constructor(cmd, opts) {
2476
+ super(["zremrangebylex", ...cmd], opts);
2477
+ }
2478
+ };
2479
+
2480
+ // pkg/commands/zremrangebyrank.ts
2481
+ var ZRemRangeByRankCommand = class extends Command {
2482
+ constructor(cmd, opts) {
2483
+ super(["zremrangebyrank", ...cmd], opts);
2484
+ }
2485
+ };
2486
+
2487
+ // pkg/commands/zremrangebyscore.ts
2488
+ var ZRemRangeByScoreCommand = class extends Command {
2489
+ constructor(cmd, opts) {
2490
+ super(["zremrangebyscore", ...cmd], opts);
2491
+ }
2492
+ };
2493
+
2494
+ // pkg/commands/zrevrank.ts
2495
+ var ZRevRankCommand = class extends Command {
2496
+ constructor(cmd, opts) {
2497
+ super(["zrevrank", ...cmd], opts);
2498
+ }
2499
+ };
2500
+
2501
+ // pkg/commands/zscan.ts
2502
+ var ZScanCommand = class extends Command {
2503
+ constructor([key, cursor, opts], cmdOpts) {
2504
+ const command = ["zscan", key, cursor];
2505
+ if (opts?.match) {
2506
+ command.push("match", opts.match);
2507
+ }
2508
+ if (typeof opts?.count === "number") {
2509
+ command.push("count", opts.count);
2510
+ }
2511
+ super(command, {
2512
+ deserialize: deserializeScanResponse,
2513
+ ...cmdOpts
2514
+ });
2515
+ }
2516
+ };
2517
+
2518
+ // pkg/commands/zscore.ts
2519
+ var ZScoreCommand = class extends Command {
2520
+ constructor(cmd, opts) {
2521
+ super(["zscore", ...cmd], opts);
2522
+ }
2523
+ };
2524
+
2525
+ // pkg/commands/zunion.ts
2526
+ var ZUnionCommand = class extends Command {
2527
+ constructor([numKeys, keyOrKeys, opts], cmdOpts) {
2528
+ const command = ["zunion", numKeys];
2529
+ if (Array.isArray(keyOrKeys)) {
2530
+ command.push(...keyOrKeys);
2531
+ } else {
2532
+ command.push(keyOrKeys);
2533
+ }
2534
+ if (opts) {
2535
+ if ("weights" in opts && opts.weights) {
2536
+ command.push("weights", ...opts.weights);
2537
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2538
+ command.push("weights", opts.weight);
2539
+ }
2540
+ if ("aggregate" in opts) {
2541
+ command.push("aggregate", opts.aggregate);
2542
+ }
2543
+ if (opts.withScores) {
2544
+ command.push("withscores");
2545
+ }
2546
+ }
2547
+ super(command, cmdOpts);
2548
+ }
2549
+ };
2550
+
2551
+ // pkg/commands/zunionstore.ts
2552
+ var ZUnionStoreCommand = class extends Command {
2553
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
2554
+ const command = ["zunionstore", destination, numKeys];
2555
+ if (Array.isArray(keyOrKeys)) {
2556
+ command.push(...keyOrKeys);
2557
+ } else {
2558
+ command.push(keyOrKeys);
2559
+ }
2560
+ if (opts) {
2561
+ if ("weights" in opts && opts.weights) {
2562
+ command.push("weights", ...opts.weights);
2563
+ } else if ("weight" in opts && typeof opts.weight === "number") {
2564
+ command.push("weights", opts.weight);
2565
+ }
2566
+ if ("aggregate" in opts) {
2567
+ command.push("aggregate", opts.aggregate);
2568
+ }
2569
+ }
2570
+ super(command, cmdOpts);
2571
+ }
2572
+ };
2573
+
2574
+ // pkg/commands/zdiffstore.ts
2575
+ var ZDiffStoreCommand = class extends Command {
2576
+ constructor(cmd, opts) {
2577
+ super(["zdiffstore", ...cmd], opts);
2578
+ }
2579
+ };
2580
+
2581
+ // pkg/commands/zmscore.ts
2582
+ var ZMScoreCommand = class extends Command {
2583
+ constructor(cmd, opts) {
2584
+ const [key, members] = cmd;
2585
+ super(["zmscore", key, ...members], opts);
2586
+ }
2587
+ };
2588
+
2589
+ // pkg/pipeline.ts
2590
+ var Pipeline = class {
2591
+ client;
2592
+ commands;
2593
+ commandOptions;
2594
+ multiExec;
2595
+ constructor(opts) {
2596
+ this.client = opts.client;
2597
+ this.commands = [];
2598
+ this.commandOptions = opts.commandOptions;
2599
+ this.multiExec = opts.multiExec ?? false;
2600
+ if (this.commandOptions?.latencyLogging) {
2601
+ const originalExec = this.exec.bind(this);
2602
+ this.exec = async (options) => {
2603
+ const start = performance.now();
2604
+ const result = await (options ? originalExec(options) : originalExec());
2605
+ const end = performance.now();
2606
+ const loggerResult = (end - start).toFixed(2);
2607
+ console.log(
2608
+ `Latency for \x1B[38;2;19;185;39m${this.multiExec ? ["MULTI-EXEC"] : ["PIPELINE"].toString().toUpperCase()}\x1B[0m: \x1B[38;2;0;255;255m${loggerResult} ms\x1B[0m`
2609
+ );
2610
+ return result;
2611
+ };
2612
+ }
2613
+ }
2614
+ exec = async (options) => {
2615
+ if (this.commands.length === 0) {
2616
+ throw new Error("Pipeline is empty");
2617
+ }
2618
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
2619
+ const res = await this.client.request({
2620
+ path,
2621
+ body: Object.values(this.commands).map((c) => c.command)
2622
+ });
2623
+ return options?.keepErrors ? res.map(({ error, result }, i) => {
2624
+ return {
2625
+ error,
2626
+ result: this.commands[i].deserialize(result)
2627
+ };
2628
+ }) : res.map(({ error, result }, i) => {
2629
+ if (error) {
2630
+ throw new UpstashError(
2631
+ `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`
2632
+ );
2633
+ }
2634
+ return this.commands[i].deserialize(result);
2635
+ });
2636
+ };
2637
+ /**
2638
+ * Returns the length of pipeline before the execution
2639
+ */
2640
+ length() {
2641
+ return this.commands.length;
2642
+ }
2643
+ /**
2644
+ * Pushes a command into the pipeline and returns a chainable instance of the
2645
+ * pipeline
2646
+ */
2647
+ chain(command) {
2648
+ this.commands.push(command);
2649
+ return this;
2650
+ }
2651
+ /**
2652
+ * @see https://redis.io/commands/append
2653
+ */
2654
+ append = (...args) => this.chain(new AppendCommand(args, this.commandOptions));
2655
+ /**
2656
+ * @see https://redis.io/commands/bitcount
2657
+ */
2658
+ bitcount = (...args) => this.chain(new BitCountCommand(args, this.commandOptions));
2659
+ /**
2660
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
2661
+ *
2662
+ * @example
2663
+ * ```typescript
2664
+ * redis.set("mykey", 0);
2665
+ * const result = await redis.pipeline()
2666
+ * .bitfield("mykey")
2667
+ * .set("u4", 0, 16)
2668
+ * .incr("u4", "#1", 1)
2669
+ * .exec();
2670
+ * console.log(result); // [[0, 1]]
2671
+ * ```
2672
+ *
2673
+ * @see https://redis.io/commands/bitfield
2674
+ */
2675
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.commandOptions, this.chain.bind(this));
2676
+ /**
2677
+ * @see https://redis.io/commands/bitop
2678
+ */
2679
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => this.chain(
2680
+ new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.commandOptions)
2681
+ );
2682
+ /**
2683
+ * @see https://redis.io/commands/bitpos
2684
+ */
2685
+ bitpos = (...args) => this.chain(new BitPosCommand(args, this.commandOptions));
2686
+ /**
2687
+ * @see https://redis.io/commands/client-setinfo
2688
+ */
2689
+ clientSetinfo = (...args) => this.chain(new ClientSetInfoCommand(args, this.commandOptions));
2690
+ /**
2691
+ * @see https://redis.io/commands/copy
2692
+ */
2693
+ copy = (...args) => this.chain(new CopyCommand(args, this.commandOptions));
2694
+ /**
2695
+ * @see https://redis.io/commands/zdiffstore
2696
+ */
2697
+ zdiffstore = (...args) => this.chain(new ZDiffStoreCommand(args, this.commandOptions));
2698
+ /**
2699
+ * @see https://redis.io/commands/dbsize
2700
+ */
2701
+ dbsize = () => this.chain(new DBSizeCommand(this.commandOptions));
2702
+ /**
2703
+ * @see https://redis.io/commands/decr
2704
+ */
2705
+ decr = (...args) => this.chain(new DecrCommand(args, this.commandOptions));
2706
+ /**
2707
+ * @see https://redis.io/commands/decrby
2708
+ */
2709
+ decrby = (...args) => this.chain(new DecrByCommand(args, this.commandOptions));
2710
+ /**
2711
+ * @see https://redis.io/commands/del
2712
+ */
2713
+ del = (...args) => this.chain(new DelCommand(args, this.commandOptions));
2714
+ /**
2715
+ * @see https://redis.io/commands/echo
2716
+ */
2717
+ echo = (...args) => this.chain(new EchoCommand(args, this.commandOptions));
2718
+ /**
2719
+ * @see https://redis.io/commands/eval_ro
2720
+ */
2721
+ evalRo = (...args) => this.chain(new EvalROCommand(args, this.commandOptions));
2722
+ /**
2723
+ * @see https://redis.io/commands/eval
2724
+ */
2725
+ eval = (...args) => this.chain(new EvalCommand(args, this.commandOptions));
2726
+ /**
2727
+ * @see https://redis.io/commands/evalsha_ro
2728
+ */
2729
+ evalshaRo = (...args) => this.chain(new EvalshaROCommand(args, this.commandOptions));
2730
+ /**
2731
+ * @see https://redis.io/commands/evalsha
2732
+ */
2733
+ evalsha = (...args) => this.chain(new EvalshaCommand(args, this.commandOptions));
2734
+ /**
2735
+ * @see https://redis.io/commands/exists
2736
+ */
2737
+ exists = (...args) => this.chain(new ExistsCommand(args, this.commandOptions));
2738
+ /**
2739
+ * @see https://redis.io/commands/expire
2740
+ */
2741
+ expire = (...args) => this.chain(new ExpireCommand(args, this.commandOptions));
2742
+ /**
2743
+ * @see https://redis.io/commands/expireat
2744
+ */
2745
+ expireat = (...args) => this.chain(new ExpireAtCommand(args, this.commandOptions));
2746
+ /**
2747
+ * @see https://redis.io/commands/flushall
2748
+ */
2749
+ flushall = (args) => this.chain(new FlushAllCommand(args, this.commandOptions));
2750
+ /**
2751
+ * @see https://redis.io/commands/flushdb
2752
+ */
2753
+ flushdb = (...args) => this.chain(new FlushDBCommand(args, this.commandOptions));
2754
+ /**
2755
+ * @see https://redis.io/commands/geoadd
2756
+ */
2757
+ geoadd = (...args) => this.chain(new GeoAddCommand(args, this.commandOptions));
2758
+ /**
2759
+ * @see https://redis.io/commands/geodist
2760
+ */
2761
+ geodist = (...args) => this.chain(new GeoDistCommand(args, this.commandOptions));
2762
+ /**
2763
+ * @see https://redis.io/commands/geopos
2764
+ */
2765
+ geopos = (...args) => this.chain(new GeoPosCommand(args, this.commandOptions));
2766
+ /**
2767
+ * @see https://redis.io/commands/geohash
2768
+ */
2769
+ geohash = (...args) => this.chain(new GeoHashCommand(args, this.commandOptions));
2770
+ /**
2771
+ * @see https://redis.io/commands/geosearch
2772
+ */
2773
+ geosearch = (...args) => this.chain(new GeoSearchCommand(args, this.commandOptions));
2774
+ /**
2775
+ * @see https://redis.io/commands/geosearchstore
2776
+ */
2777
+ geosearchstore = (...args) => this.chain(new GeoSearchStoreCommand(args, this.commandOptions));
2778
+ /**
2779
+ * @see https://redis.io/commands/get
2780
+ */
2781
+ get = (...args) => this.chain(new GetCommand(args, this.commandOptions));
2782
+ /**
2783
+ * @see https://redis.io/commands/getbit
2784
+ */
2785
+ getbit = (...args) => this.chain(new GetBitCommand(args, this.commandOptions));
2786
+ /**
2787
+ * @see https://redis.io/commands/getdel
2788
+ */
2789
+ getdel = (...args) => this.chain(new GetDelCommand(args, this.commandOptions));
2790
+ /**
2791
+ * @see https://redis.io/commands/getex
2792
+ */
2793
+ getex = (...args) => this.chain(new GetExCommand(args, this.commandOptions));
2794
+ /**
2795
+ * @see https://redis.io/commands/getrange
2796
+ */
2797
+ getrange = (...args) => this.chain(new GetRangeCommand(args, this.commandOptions));
2798
+ /**
2799
+ * @see https://redis.io/commands/getset
2800
+ */
2801
+ getset = (key, value) => this.chain(new GetSetCommand([key, value], this.commandOptions));
2802
+ /**
2803
+ * @see https://redis.io/commands/hdel
2804
+ */
2805
+ hdel = (...args) => this.chain(new HDelCommand(args, this.commandOptions));
2806
+ /**
2807
+ * @see https://redis.io/commands/hexists
2808
+ */
2809
+ hexists = (...args) => this.chain(new HExistsCommand(args, this.commandOptions));
2810
+ /**
2811
+ * @see https://redis.io/commands/hexpire
2812
+ */
2813
+ hexpire = (...args) => this.chain(new HExpireCommand(args, this.commandOptions));
2814
+ /**
2815
+ * @see https://redis.io/commands/hexpireat
2816
+ */
2817
+ hexpireat = (...args) => this.chain(new HExpireAtCommand(args, this.commandOptions));
2818
+ /**
2819
+ * @see https://redis.io/commands/hexpiretime
2820
+ */
2821
+ hexpiretime = (...args) => this.chain(new HExpireTimeCommand(args, this.commandOptions));
2822
+ /**
2823
+ * @see https://redis.io/commands/httl
2824
+ */
2825
+ httl = (...args) => this.chain(new HTtlCommand(args, this.commandOptions));
2826
+ /**
2827
+ * @see https://redis.io/commands/hpexpire
2828
+ */
2829
+ hpexpire = (...args) => this.chain(new HPExpireCommand(args, this.commandOptions));
2830
+ /**
2831
+ * @see https://redis.io/commands/hpexpireat
2832
+ */
2833
+ hpexpireat = (...args) => this.chain(new HPExpireAtCommand(args, this.commandOptions));
2834
+ /**
2835
+ * @see https://redis.io/commands/hpexpiretime
2836
+ */
2837
+ hpexpiretime = (...args) => this.chain(new HPExpireTimeCommand(args, this.commandOptions));
2838
+ /**
2839
+ * @see https://redis.io/commands/hpttl
2840
+ */
2841
+ hpttl = (...args) => this.chain(new HPTtlCommand(args, this.commandOptions));
2842
+ /**
2843
+ * @see https://redis.io/commands/hpersist
2844
+ */
2845
+ hpersist = (...args) => this.chain(new HPersistCommand(args, this.commandOptions));
2846
+ /**
2847
+ * @see https://redis.io/commands/hget
2848
+ */
2849
+ hget = (...args) => this.chain(new HGetCommand(args, this.commandOptions));
2850
+ /**
2851
+ * @see https://redis.io/commands/hgetall
2852
+ */
2853
+ hgetall = (...args) => this.chain(new HGetAllCommand(args, this.commandOptions));
2854
+ /**
2855
+ * @see https://redis.io/commands/hgetdel
2856
+ */
2857
+ hgetdel = (...args) => this.chain(new HGetDelCommand(args, this.commandOptions));
2858
+ /**
2859
+ * @see https://redis.io/commands/hgetex
2860
+ */
2861
+ hgetex = (...args) => this.chain(new HGetExCommand(args, this.commandOptions));
2862
+ /**
2863
+ * @see https://redis.io/commands/hincrby
2864
+ */
2865
+ hincrby = (...args) => this.chain(new HIncrByCommand(args, this.commandOptions));
2866
+ /**
2867
+ * @see https://redis.io/commands/hincrbyfloat
2868
+ */
2869
+ hincrbyfloat = (...args) => this.chain(new HIncrByFloatCommand(args, this.commandOptions));
2870
+ /**
2871
+ * @see https://redis.io/commands/hkeys
2872
+ */
2873
+ hkeys = (...args) => this.chain(new HKeysCommand(args, this.commandOptions));
2874
+ /**
2875
+ * @see https://redis.io/commands/hlen
2876
+ */
2877
+ hlen = (...args) => this.chain(new HLenCommand(args, this.commandOptions));
2878
+ /**
2879
+ * @see https://redis.io/commands/hmget
2880
+ */
2881
+ hmget = (...args) => this.chain(new HMGetCommand(args, this.commandOptions));
2882
+ /**
2883
+ * @see https://redis.io/commands/hmset
2884
+ */
2885
+ hmset = (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions));
2886
+ /**
2887
+ * @see https://redis.io/commands/hrandfield
2888
+ */
2889
+ hrandfield = (key, count, withValues) => this.chain(new HRandFieldCommand([key, count, withValues], this.commandOptions));
2890
+ /**
2891
+ * @see https://redis.io/commands/hscan
2892
+ */
2893
+ hscan = (...args) => this.chain(new HScanCommand(args, this.commandOptions));
2894
+ /**
2895
+ * @see https://redis.io/commands/hset
2896
+ */
2897
+ hset = (key, kv) => this.chain(new HSetCommand([key, kv], this.commandOptions));
2898
+ /**
2899
+ * @see https://redis.io/commands/hsetex
2900
+ */
2901
+ hsetex = (...args) => this.chain(new HSetExCommand(args, this.commandOptions));
2902
+ /**
2903
+ * @see https://redis.io/commands/hsetnx
2904
+ */
2905
+ hsetnx = (key, field, value) => this.chain(new HSetNXCommand([key, field, value], this.commandOptions));
2906
+ /**
2907
+ * @see https://redis.io/commands/hstrlen
2908
+ */
2909
+ hstrlen = (...args) => this.chain(new HStrLenCommand(args, this.commandOptions));
2910
+ /**
2911
+ * @see https://redis.io/commands/hvals
2912
+ */
2913
+ hvals = (...args) => this.chain(new HValsCommand(args, this.commandOptions));
2914
+ /**
2915
+ * @see https://redis.io/commands/incr
2916
+ */
2917
+ incr = (...args) => this.chain(new IncrCommand(args, this.commandOptions));
2918
+ /**
2919
+ * @see https://redis.io/commands/incrby
2920
+ */
2921
+ incrby = (...args) => this.chain(new IncrByCommand(args, this.commandOptions));
2922
+ /**
2923
+ * @see https://redis.io/commands/incrbyfloat
2924
+ */
2925
+ incrbyfloat = (...args) => this.chain(new IncrByFloatCommand(args, this.commandOptions));
2926
+ /**
2927
+ * @see https://redis.io/commands/keys
2928
+ */
2929
+ keys = (...args) => this.chain(new KeysCommand(args, this.commandOptions));
2930
+ /**
2931
+ * @see https://redis.io/commands/lindex
2932
+ */
2933
+ lindex = (...args) => this.chain(new LIndexCommand(args, this.commandOptions));
2934
+ /**
2935
+ * @see https://redis.io/commands/linsert
2936
+ */
2937
+ linsert = (key, direction, pivot, value) => this.chain(new LInsertCommand([key, direction, pivot, value], this.commandOptions));
2938
+ /**
2939
+ * @see https://redis.io/commands/llen
2940
+ */
2941
+ llen = (...args) => this.chain(new LLenCommand(args, this.commandOptions));
2942
+ /**
2943
+ * @see https://redis.io/commands/lmove
2944
+ */
2945
+ lmove = (...args) => this.chain(new LMoveCommand(args, this.commandOptions));
2946
+ /**
2947
+ * @see https://redis.io/commands/lpop
2948
+ */
2949
+ lpop = (...args) => this.chain(new LPopCommand(args, this.commandOptions));
2950
+ /**
2951
+ * @see https://redis.io/commands/lmpop
2952
+ */
2953
+ lmpop = (...args) => this.chain(new LmPopCommand(args, this.commandOptions));
2954
+ /**
2955
+ * @see https://redis.io/commands/lpos
2956
+ */
2957
+ lpos = (...args) => this.chain(new LPosCommand(args, this.commandOptions));
2958
+ /**
2959
+ * @see https://redis.io/commands/lpush
2960
+ */
2961
+ lpush = (key, ...elements) => this.chain(new LPushCommand([key, ...elements], this.commandOptions));
2962
+ /**
2963
+ * @see https://redis.io/commands/lpushx
2964
+ */
2965
+ lpushx = (key, ...elements) => this.chain(new LPushXCommand([key, ...elements], this.commandOptions));
2966
+ /**
2967
+ * @see https://redis.io/commands/lrange
2968
+ */
2969
+ lrange = (...args) => this.chain(new LRangeCommand(args, this.commandOptions));
2970
+ /**
2971
+ * @see https://redis.io/commands/lrem
2972
+ */
2973
+ lrem = (key, count, value) => this.chain(new LRemCommand([key, count, value], this.commandOptions));
2974
+ /**
2975
+ * @see https://redis.io/commands/lset
2976
+ */
2977
+ lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
2978
+ /**
2979
+ * @see https://redis.io/commands/ltrim
2980
+ */
2981
+ ltrim = (...args) => this.chain(new LTrimCommand(args, this.commandOptions));
2982
+ /**
2983
+ * @see https://redis.io/commands/mget
2984
+ */
2985
+ mget = (...args) => this.chain(new MGetCommand(args, this.commandOptions));
2986
+ /**
2987
+ * @see https://redis.io/commands/mset
2988
+ */
2989
+ mset = (kv) => this.chain(new MSetCommand([kv], this.commandOptions));
2990
+ /**
2991
+ * @see https://redis.io/commands/msetnx
2992
+ */
2993
+ msetnx = (kv) => this.chain(new MSetNXCommand([kv], this.commandOptions));
2994
+ /**
2995
+ * @see https://redis.io/commands/persist
2996
+ */
2997
+ persist = (...args) => this.chain(new PersistCommand(args, this.commandOptions));
2998
+ /**
2999
+ * @see https://redis.io/commands/pexpire
3000
+ */
3001
+ pexpire = (...args) => this.chain(new PExpireCommand(args, this.commandOptions));
3002
+ /**
3003
+ * @see https://redis.io/commands/pexpireat
3004
+ */
3005
+ pexpireat = (...args) => this.chain(new PExpireAtCommand(args, this.commandOptions));
3006
+ /**
3007
+ * @see https://redis.io/commands/pfadd
3008
+ */
3009
+ pfadd = (...args) => this.chain(new PfAddCommand(args, this.commandOptions));
3010
+ /**
3011
+ * @see https://redis.io/commands/pfcount
3012
+ */
3013
+ pfcount = (...args) => this.chain(new PfCountCommand(args, this.commandOptions));
3014
+ /**
3015
+ * @see https://redis.io/commands/pfmerge
3016
+ */
3017
+ pfmerge = (...args) => this.chain(new PfMergeCommand(args, this.commandOptions));
3018
+ /**
3019
+ * @see https://redis.io/commands/ping
3020
+ */
3021
+ ping = (args) => this.chain(new PingCommand(args, this.commandOptions));
3022
+ /**
3023
+ * @see https://redis.io/commands/psetex
3024
+ */
3025
+ psetex = (key, ttl, value) => this.chain(new PSetEXCommand([key, ttl, value], this.commandOptions));
3026
+ /**
3027
+ * @see https://redis.io/commands/pttl
3028
+ */
3029
+ pttl = (...args) => this.chain(new PTtlCommand(args, this.commandOptions));
3030
+ /**
3031
+ * @see https://redis.io/commands/publish
3032
+ */
3033
+ publish = (...args) => this.chain(new PublishCommand(args, this.commandOptions));
3034
+ /**
3035
+ * @see https://redis.io/commands/randomkey
3036
+ */
3037
+ randomkey = () => this.chain(new RandomKeyCommand(this.commandOptions));
3038
+ /**
3039
+ * @see https://redis.io/commands/rename
3040
+ */
3041
+ rename = (...args) => this.chain(new RenameCommand(args, this.commandOptions));
3042
+ /**
3043
+ * @see https://redis.io/commands/renamenx
3044
+ */
3045
+ renamenx = (...args) => this.chain(new RenameNXCommand(args, this.commandOptions));
3046
+ /**
3047
+ * @see https://redis.io/commands/rpop
3048
+ */
3049
+ rpop = (...args) => this.chain(new RPopCommand(args, this.commandOptions));
3050
+ /**
3051
+ * @see https://redis.io/commands/rpush
3052
+ */
3053
+ rpush = (key, ...elements) => this.chain(new RPushCommand([key, ...elements], this.commandOptions));
3054
+ /**
3055
+ * @see https://redis.io/commands/rpushx
3056
+ */
3057
+ rpushx = (key, ...elements) => this.chain(new RPushXCommand([key, ...elements], this.commandOptions));
3058
+ /**
3059
+ * @see https://redis.io/commands/sadd
3060
+ */
3061
+ sadd = (key, member, ...members) => this.chain(new SAddCommand([key, member, ...members], this.commandOptions));
3062
+ /**
3063
+ * @see https://redis.io/commands/scan
3064
+ */
3065
+ scan = (...args) => this.chain(new ScanCommand(args, this.commandOptions));
3066
+ /**
3067
+ * @see https://redis.io/commands/scard
3068
+ */
3069
+ scard = (...args) => this.chain(new SCardCommand(args, this.commandOptions));
3070
+ /**
3071
+ * @see https://redis.io/commands/script-exists
3072
+ */
3073
+ scriptExists = (...args) => this.chain(new ScriptExistsCommand(args, this.commandOptions));
3074
+ /**
3075
+ * @see https://redis.io/commands/script-flush
3076
+ */
3077
+ scriptFlush = (...args) => this.chain(new ScriptFlushCommand(args, this.commandOptions));
3078
+ /**
3079
+ * @see https://redis.io/commands/script-load
3080
+ */
3081
+ scriptLoad = (...args) => this.chain(new ScriptLoadCommand(args, this.commandOptions));
3082
+ /*)*
3083
+ * @see https://redis.io/commands/sdiff
3084
+ */
3085
+ sdiff = (...args) => this.chain(new SDiffCommand(args, this.commandOptions));
3086
+ /**
3087
+ * @see https://redis.io/commands/sdiffstore
3088
+ */
3089
+ sdiffstore = (...args) => this.chain(new SDiffStoreCommand(args, this.commandOptions));
3090
+ /**
3091
+ * @see https://redis.io/commands/set
3092
+ */
3093
+ set = (key, value, opts) => this.chain(new SetCommand([key, value, opts], this.commandOptions));
3094
+ /**
3095
+ * @see https://redis.io/commands/setbit
3096
+ */
3097
+ setbit = (...args) => this.chain(new SetBitCommand(args, this.commandOptions));
3098
+ /**
3099
+ * @see https://redis.io/commands/setex
3100
+ */
3101
+ setex = (key, ttl, value) => this.chain(new SetExCommand([key, ttl, value], this.commandOptions));
3102
+ /**
3103
+ * @see https://redis.io/commands/setnx
3104
+ */
3105
+ setnx = (key, value) => this.chain(new SetNxCommand([key, value], this.commandOptions));
3106
+ /**
3107
+ * @see https://redis.io/commands/setrange
3108
+ */
3109
+ setrange = (...args) => this.chain(new SetRangeCommand(args, this.commandOptions));
3110
+ /**
3111
+ * @see https://redis.io/commands/sinter
3112
+ */
3113
+ sinter = (...args) => this.chain(new SInterCommand(args, this.commandOptions));
3114
+ /**
3115
+ * @see https://redis.io/commands/sinterstore
3116
+ */
3117
+ sinterstore = (...args) => this.chain(new SInterStoreCommand(args, this.commandOptions));
3118
+ /**
3119
+ * @see https://redis.io/commands/sismember
3120
+ */
3121
+ sismember = (key, member) => this.chain(new SIsMemberCommand([key, member], this.commandOptions));
3122
+ /**
3123
+ * @see https://redis.io/commands/smembers
3124
+ */
3125
+ smembers = (...args) => this.chain(new SMembersCommand(args, this.commandOptions));
3126
+ /**
3127
+ * @see https://redis.io/commands/smismember
3128
+ */
3129
+ smismember = (key, members) => this.chain(new SMIsMemberCommand([key, members], this.commandOptions));
3130
+ /**
3131
+ * @see https://redis.io/commands/smove
3132
+ */
3133
+ smove = (source, destination, member) => this.chain(new SMoveCommand([source, destination, member], this.commandOptions));
3134
+ /**
3135
+ * @see https://redis.io/commands/spop
3136
+ */
3137
+ spop = (...args) => this.chain(new SPopCommand(args, this.commandOptions));
3138
+ /**
3139
+ * @see https://redis.io/commands/srandmember
3140
+ */
3141
+ srandmember = (...args) => this.chain(new SRandMemberCommand(args, this.commandOptions));
3142
+ /**
3143
+ * @see https://redis.io/commands/srem
3144
+ */
3145
+ srem = (key, ...members) => this.chain(new SRemCommand([key, ...members], this.commandOptions));
3146
+ /**
3147
+ * @see https://redis.io/commands/sscan
3148
+ */
3149
+ sscan = (...args) => this.chain(new SScanCommand(args, this.commandOptions));
3150
+ /**
3151
+ * @see https://redis.io/commands/strlen
3152
+ */
3153
+ strlen = (...args) => this.chain(new StrLenCommand(args, this.commandOptions));
3154
+ /**
3155
+ * @see https://redis.io/commands/sunion
3156
+ */
3157
+ sunion = (...args) => this.chain(new SUnionCommand(args, this.commandOptions));
3158
+ /**
3159
+ * @see https://redis.io/commands/sunionstore
3160
+ */
3161
+ sunionstore = (...args) => this.chain(new SUnionStoreCommand(args, this.commandOptions));
3162
+ /**
3163
+ * @see https://redis.io/commands/time
3164
+ */
3165
+ time = () => this.chain(new TimeCommand(this.commandOptions));
3166
+ /**
3167
+ * @see https://redis.io/commands/touch
3168
+ */
3169
+ touch = (...args) => this.chain(new TouchCommand(args, this.commandOptions));
3170
+ /**
3171
+ * @see https://redis.io/commands/ttl
3172
+ */
3173
+ ttl = (...args) => this.chain(new TtlCommand(args, this.commandOptions));
3174
+ /**
3175
+ * @see https://redis.io/commands/type
3176
+ */
3177
+ type = (...args) => this.chain(new TypeCommand(args, this.commandOptions));
3178
+ /**
3179
+ * @see https://redis.io/commands/unlink
3180
+ */
3181
+ unlink = (...args) => this.chain(new UnlinkCommand(args, this.commandOptions));
3182
+ /**
3183
+ * @see https://redis.io/commands/zadd
3184
+ */
3185
+ zadd = (...args) => {
3186
+ if ("score" in args[1]) {
3187
+ return this.chain(
3188
+ new ZAddCommand([args[0], args[1], ...args.slice(2)], this.commandOptions)
3189
+ );
3190
+ }
3191
+ return this.chain(
3192
+ new ZAddCommand(
3193
+ [args[0], args[1], ...args.slice(2)],
3194
+ this.commandOptions
3195
+ )
3196
+ );
3197
+ };
3198
+ /**
3199
+ * @see https://redis.io/commands/xadd
3200
+ */
3201
+ xadd = (...args) => this.chain(new XAddCommand(args, this.commandOptions));
3202
+ /**
3203
+ * @see https://redis.io/commands/xack
3204
+ */
3205
+ xack = (...args) => this.chain(new XAckCommand(args, this.commandOptions));
3206
+ /**
3207
+ * @see https://redis.io/commands/xackdel
3208
+ */
3209
+ xackdel = (...args) => this.chain(new XAckDelCommand(args, this.commandOptions));
3210
+ /**
3211
+ * @see https://redis.io/commands/xdel
3212
+ */
3213
+ xdel = (...args) => this.chain(new XDelCommand(args, this.commandOptions));
3214
+ /**
3215
+ * @see https://redis.io/commands/xdelex
3216
+ */
3217
+ xdelex = (...args) => this.chain(new XDelExCommand(args, this.commandOptions));
3218
+ /**
3219
+ * @see https://redis.io/commands/xgroup
3220
+ */
3221
+ xgroup = (...args) => this.chain(new XGroupCommand(args, this.commandOptions));
3222
+ /**
3223
+ * @see https://redis.io/commands/xread
3224
+ */
3225
+ xread = (...args) => this.chain(new XReadCommand(args, this.commandOptions));
3226
+ /**
3227
+ * @see https://redis.io/commands/xreadgroup
3228
+ */
3229
+ xreadgroup = (...args) => this.chain(new XReadGroupCommand(args, this.commandOptions));
3230
+ /**
3231
+ * @see https://redis.io/commands/xinfo
3232
+ */
3233
+ xinfo = (...args) => this.chain(new XInfoCommand(args, this.commandOptions));
3234
+ /**
3235
+ * @see https://redis.io/commands/xlen
3236
+ */
3237
+ xlen = (...args) => this.chain(new XLenCommand(args, this.commandOptions));
3238
+ /**
3239
+ * @see https://redis.io/commands/xpending
3240
+ */
3241
+ xpending = (...args) => this.chain(new XPendingCommand(args, this.commandOptions));
3242
+ /**
3243
+ * @see https://redis.io/commands/xclaim
3244
+ */
3245
+ xclaim = (...args) => this.chain(new XClaimCommand(args, this.commandOptions));
3246
+ /**
3247
+ * @see https://redis.io/commands/xautoclaim
3248
+ */
3249
+ xautoclaim = (...args) => this.chain(new XAutoClaim(args, this.commandOptions));
3250
+ /**
3251
+ * @see https://redis.io/commands/xtrim
3252
+ */
3253
+ xtrim = (...args) => this.chain(new XTrimCommand(args, this.commandOptions));
3254
+ /**
3255
+ * @see https://redis.io/commands/xrange
3256
+ */
3257
+ xrange = (...args) => this.chain(new XRangeCommand(args, this.commandOptions));
3258
+ /**
3259
+ * @see https://redis.io/commands/xrevrange
3260
+ */
3261
+ xrevrange = (...args) => this.chain(new XRevRangeCommand(args, this.commandOptions));
3262
+ /**
3263
+ * @see https://redis.io/commands/zcard
3264
+ */
3265
+ zcard = (...args) => this.chain(new ZCardCommand(args, this.commandOptions));
3266
+ /**
3267
+ * @see https://redis.io/commands/zcount
3268
+ */
3269
+ zcount = (...args) => this.chain(new ZCountCommand(args, this.commandOptions));
3270
+ /**
3271
+ * @see https://redis.io/commands/zincrby
3272
+ */
3273
+ zincrby = (key, increment, member) => this.chain(new ZIncrByCommand([key, increment, member], this.commandOptions));
3274
+ /**
3275
+ * @see https://redis.io/commands/zinterstore
3276
+ */
3277
+ zinterstore = (...args) => this.chain(new ZInterStoreCommand(args, this.commandOptions));
3278
+ /**
3279
+ * @see https://redis.io/commands/zlexcount
3280
+ */
3281
+ zlexcount = (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions));
3282
+ /**
3283
+ * @see https://redis.io/commands/zmscore
3284
+ */
3285
+ zmscore = (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions));
3286
+ /**
3287
+ * @see https://redis.io/commands/zpopmax
3288
+ */
3289
+ zpopmax = (...args) => this.chain(new ZPopMaxCommand(args, this.commandOptions));
3290
+ /**
3291
+ * @see https://redis.io/commands/zpopmin
3292
+ */
3293
+ zpopmin = (...args) => this.chain(new ZPopMinCommand(args, this.commandOptions));
3294
+ /**
3295
+ * @see https://redis.io/commands/zrange
3296
+ */
3297
+ zrange = (...args) => this.chain(new ZRangeCommand(args, this.commandOptions));
3298
+ /**
3299
+ * @see https://redis.io/commands/zrank
3300
+ */
3301
+ zrank = (key, member) => this.chain(new ZRankCommand([key, member], this.commandOptions));
3302
+ /**
3303
+ * @see https://redis.io/commands/zrem
3304
+ */
3305
+ zrem = (key, ...members) => this.chain(new ZRemCommand([key, ...members], this.commandOptions));
3306
+ /**
3307
+ * @see https://redis.io/commands/zremrangebylex
3308
+ */
3309
+ zremrangebylex = (...args) => this.chain(new ZRemRangeByLexCommand(args, this.commandOptions));
3310
+ /**
3311
+ * @see https://redis.io/commands/zremrangebyrank
3312
+ */
3313
+ zremrangebyrank = (...args) => this.chain(new ZRemRangeByRankCommand(args, this.commandOptions));
3314
+ /**
3315
+ * @see https://redis.io/commands/zremrangebyscore
3316
+ */
3317
+ zremrangebyscore = (...args) => this.chain(new ZRemRangeByScoreCommand(args, this.commandOptions));
3318
+ /**
3319
+ * @see https://redis.io/commands/zrevrank
3320
+ */
3321
+ zrevrank = (key, member) => this.chain(new ZRevRankCommand([key, member], this.commandOptions));
3322
+ /**
3323
+ * @see https://redis.io/commands/zscan
3324
+ */
3325
+ zscan = (...args) => this.chain(new ZScanCommand(args, this.commandOptions));
3326
+ /**
3327
+ * @see https://redis.io/commands/zscore
3328
+ */
3329
+ zscore = (key, member) => this.chain(new ZScoreCommand([key, member], this.commandOptions));
3330
+ /**
3331
+ * @see https://redis.io/commands/zunionstore
3332
+ */
3333
+ zunionstore = (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions));
3334
+ /**
3335
+ * @see https://redis.io/commands/zunion
3336
+ */
3337
+ zunion = (...args) => this.chain(new ZUnionCommand(args, this.commandOptions));
3338
+ /**
3339
+ * @see https://redis.io/commands/?group=json
3340
+ */
3341
+ get json() {
3342
+ return {
3343
+ /**
3344
+ * @see https://redis.io/commands/json.arrappend
3345
+ */
3346
+ arrappend: (...args) => this.chain(new JsonArrAppendCommand(args, this.commandOptions)),
3347
+ /**
3348
+ * @see https://redis.io/commands/json.arrindex
3349
+ */
3350
+ arrindex: (...args) => this.chain(new JsonArrIndexCommand(args, this.commandOptions)),
3351
+ /**
3352
+ * @see https://redis.io/commands/json.arrinsert
3353
+ */
3354
+ arrinsert: (...args) => this.chain(new JsonArrInsertCommand(args, this.commandOptions)),
3355
+ /**
3356
+ * @see https://redis.io/commands/json.arrlen
3357
+ */
3358
+ arrlen: (...args) => this.chain(new JsonArrLenCommand(args, this.commandOptions)),
3359
+ /**
3360
+ * @see https://redis.io/commands/json.arrpop
3361
+ */
3362
+ arrpop: (...args) => this.chain(new JsonArrPopCommand(args, this.commandOptions)),
3363
+ /**
3364
+ * @see https://redis.io/commands/json.arrtrim
3365
+ */
3366
+ arrtrim: (...args) => this.chain(new JsonArrTrimCommand(args, this.commandOptions)),
3367
+ /**
3368
+ * @see https://redis.io/commands/json.clear
3369
+ */
3370
+ clear: (...args) => this.chain(new JsonClearCommand(args, this.commandOptions)),
3371
+ /**
3372
+ * @see https://redis.io/commands/json.del
3373
+ */
3374
+ del: (...args) => this.chain(new JsonDelCommand(args, this.commandOptions)),
3375
+ /**
3376
+ * @see https://redis.io/commands/json.forget
3377
+ */
3378
+ forget: (...args) => this.chain(new JsonForgetCommand(args, this.commandOptions)),
3379
+ /**
3380
+ * @see https://redis.io/commands/json.get
3381
+ */
3382
+ get: (...args) => this.chain(new JsonGetCommand(args, this.commandOptions)),
3383
+ /**
3384
+ * @see https://redis.io/commands/json.merge
3385
+ */
3386
+ merge: (...args) => this.chain(new JsonMergeCommand(args, this.commandOptions)),
3387
+ /**
3388
+ * @see https://redis.io/commands/json.mget
3389
+ */
3390
+ mget: (...args) => this.chain(new JsonMGetCommand(args, this.commandOptions)),
3391
+ /**
3392
+ * @see https://redis.io/commands/json.mset
3393
+ */
3394
+ mset: (...args) => this.chain(new JsonMSetCommand(args, this.commandOptions)),
3395
+ /**
3396
+ * @see https://redis.io/commands/json.numincrby
3397
+ */
3398
+ numincrby: (...args) => this.chain(new JsonNumIncrByCommand(args, this.commandOptions)),
3399
+ /**
3400
+ * @see https://redis.io/commands/json.nummultby
3401
+ */
3402
+ nummultby: (...args) => this.chain(new JsonNumMultByCommand(args, this.commandOptions)),
3403
+ /**
3404
+ * @see https://redis.io/commands/json.objkeys
3405
+ */
3406
+ objkeys: (...args) => this.chain(new JsonObjKeysCommand(args, this.commandOptions)),
3407
+ /**
3408
+ * @see https://redis.io/commands/json.objlen
3409
+ */
3410
+ objlen: (...args) => this.chain(new JsonObjLenCommand(args, this.commandOptions)),
3411
+ /**
3412
+ * @see https://redis.io/commands/json.resp
3413
+ */
3414
+ resp: (...args) => this.chain(new JsonRespCommand(args, this.commandOptions)),
3415
+ /**
3416
+ * @see https://redis.io/commands/json.set
3417
+ */
3418
+ set: (...args) => this.chain(new JsonSetCommand(args, this.commandOptions)),
3419
+ /**
3420
+ * @see https://redis.io/commands/json.strappend
3421
+ */
3422
+ strappend: (...args) => this.chain(new JsonStrAppendCommand(args, this.commandOptions)),
3423
+ /**
3424
+ * @see https://redis.io/commands/json.strlen
3425
+ */
3426
+ strlen: (...args) => this.chain(new JsonStrLenCommand(args, this.commandOptions)),
3427
+ /**
3428
+ * @see https://redis.io/commands/json.toggle
3429
+ */
3430
+ toggle: (...args) => this.chain(new JsonToggleCommand(args, this.commandOptions)),
3431
+ /**
3432
+ * @see https://redis.io/commands/json.type
3433
+ */
3434
+ type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
3435
+ };
3436
+ }
3437
+ get functions() {
3438
+ return {
3439
+ /**
3440
+ * @see https://redis.io/docs/latest/commands/function-load/
3441
+ */
3442
+ load: (...args) => this.chain(new FunctionLoadCommand(args, this.commandOptions)),
3443
+ /**
3444
+ * @see https://redis.io/docs/latest/commands/function-list/
3445
+ */
3446
+ list: (...args) => this.chain(new FunctionListCommand(args, this.commandOptions)),
3447
+ /**
3448
+ * @see https://redis.io/docs/latest/commands/function-delete/
3449
+ */
3450
+ delete: (...args) => this.chain(new FunctionDeleteCommand(args, this.commandOptions)),
3451
+ /**
3452
+ * @see https://redis.io/docs/latest/commands/function-flush/
3453
+ */
3454
+ flush: () => this.chain(new FunctionFlushCommand(this.commandOptions)),
3455
+ /**
3456
+ * @see https://redis.io/docs/latest/commands/function-stats/
3457
+ */
3458
+ stats: () => this.chain(new FunctionStatsCommand(this.commandOptions)),
3459
+ /**
3460
+ * @see https://redis.io/docs/latest/commands/fcall/
3461
+ */
3462
+ call: (...args) => this.chain(new FCallCommand(args, this.commandOptions)),
3463
+ /**
3464
+ * @see https://redis.io/docs/latest/commands/fcall_ro/
3465
+ */
3466
+ callRo: (...args) => this.chain(new FCallRoCommand(args, this.commandOptions))
3467
+ };
3468
+ }
3469
+ };
3470
+
3471
+ // pkg/auto-pipeline.ts
3472
+ var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
3473
+ "scan",
3474
+ "keys",
3475
+ "flushdb",
3476
+ "flushall",
3477
+ "dbsize",
3478
+ "hscan",
3479
+ "hgetall",
3480
+ "hkeys",
3481
+ "lrange",
3482
+ "sscan",
3483
+ "smembers",
3484
+ "xrange",
3485
+ "xrevrange",
3486
+ "zscan",
3487
+ "zrange",
3488
+ "exec"
3489
+ ]);
3490
+ function createAutoPipelineProxy(_redis, namespace = "root") {
3491
+ const redis = _redis;
3492
+ if (!redis.autoPipelineExecutor) {
3493
+ redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
3494
+ }
3495
+ return new Proxy(redis, {
3496
+ get: (redis2, command) => {
3497
+ if (command === "pipelineCounter") {
3498
+ return redis2.autoPipelineExecutor.pipelineCounter;
3499
+ }
3500
+ if (namespace === "root" && command === "json") {
3501
+ return createAutoPipelineProxy(redis2, "json");
3502
+ }
3503
+ if (namespace === "root" && command === "functions") {
3504
+ return createAutoPipelineProxy(redis2, "functions");
3505
+ }
3506
+ if (namespace === "root") {
3507
+ const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
3508
+ const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
3509
+ if (commandInRedisButNotPipeline || isCommandExcluded) {
3510
+ return redis2[command];
3511
+ }
3512
+ }
3513
+ const pipeline = redis2.autoPipelineExecutor.pipeline;
3514
+ const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
3515
+ const isFunction = typeof targetFunction === "function";
3516
+ if (isFunction) {
3517
+ return (...args) => {
3518
+ return redis2.autoPipelineExecutor.withAutoPipeline((pipeline2) => {
3519
+ const targetFunction2 = namespace === "json" ? pipeline2.json[command] : namespace === "functions" ? pipeline2.functions[command] : pipeline2[command];
3520
+ targetFunction2(...args);
3521
+ });
3522
+ };
3523
+ }
3524
+ return targetFunction;
3525
+ }
3526
+ });
3527
+ }
3528
+ var AutoPipelineExecutor = class {
3529
+ pipelinePromises = /* @__PURE__ */ new WeakMap();
3530
+ activePipeline = null;
3531
+ indexInCurrentPipeline = 0;
3532
+ redis;
3533
+ pipeline;
3534
+ // only to make sure that proxy can work
3535
+ pipelineCounter = 0;
3536
+ // to keep track of how many times a pipeline was executed
3537
+ constructor(redis) {
3538
+ this.redis = redis;
3539
+ this.pipeline = redis.pipeline();
3540
+ }
3541
+ async withAutoPipeline(executeWithPipeline) {
3542
+ const pipeline = this.activePipeline ?? this.redis.pipeline();
3543
+ if (!this.activePipeline) {
3544
+ this.activePipeline = pipeline;
3545
+ this.indexInCurrentPipeline = 0;
3546
+ }
3547
+ const index = this.indexInCurrentPipeline++;
3548
+ executeWithPipeline(pipeline);
3549
+ const pipelineDone = this.deferExecution().then(() => {
3550
+ if (!this.pipelinePromises.has(pipeline)) {
3551
+ const pipelinePromise = pipeline.exec({ keepErrors: true });
3552
+ this.pipelineCounter += 1;
3553
+ this.pipelinePromises.set(pipeline, pipelinePromise);
3554
+ this.activePipeline = null;
3555
+ }
3556
+ return this.pipelinePromises.get(pipeline);
3557
+ });
3558
+ const results = await pipelineDone;
3559
+ const commandResult = results[index];
3560
+ if (commandResult.error) {
3561
+ throw new UpstashError(`Command failed: ${commandResult.error}`);
3562
+ }
3563
+ return commandResult.result;
3564
+ }
3565
+ async deferExecution() {
3566
+ await Promise.resolve();
3567
+ await Promise.resolve();
3568
+ }
3569
+ };
3570
+
3571
+ // pkg/commands/psubscribe.ts
3572
+ var PSubscribeCommand = class extends Command {
3573
+ constructor(cmd, opts) {
3574
+ const sseHeaders = {
3575
+ Accept: "text/event-stream",
3576
+ "Cache-Control": "no-cache",
3577
+ Connection: "keep-alive"
3578
+ };
3579
+ super([], {
3580
+ ...opts,
3581
+ headers: sseHeaders,
3582
+ path: ["psubscribe", ...cmd],
3583
+ streamOptions: {
3584
+ isStreaming: true,
3585
+ onMessage: opts?.streamOptions?.onMessage,
3586
+ signal: opts?.streamOptions?.signal
3587
+ }
3588
+ });
3589
+ }
3590
+ };
3591
+
3592
+ // pkg/commands/subscribe.ts
3593
+ var Subscriber = class extends EventTarget {
3594
+ subscriptions;
3595
+ client;
3596
+ listeners;
3597
+ opts;
3598
+ constructor(client, channels, isPattern = false, opts) {
3599
+ super();
3600
+ this.client = client;
3601
+ this.subscriptions = /* @__PURE__ */ new Map();
3602
+ this.listeners = /* @__PURE__ */ new Map();
3603
+ this.opts = opts;
3604
+ for (const channel of channels) {
3605
+ if (isPattern) {
3606
+ this.subscribeToPattern(channel);
3607
+ } else {
3608
+ this.subscribeToChannel(channel);
3609
+ }
3610
+ }
3611
+ }
3612
+ subscribeToChannel(channel) {
3613
+ const controller = new AbortController();
3614
+ const command = new SubscribeCommand([channel], {
3615
+ streamOptions: {
3616
+ signal: controller.signal,
3617
+ onMessage: (data) => this.handleMessage(data, false)
3618
+ }
3619
+ });
3620
+ command.exec(this.client).catch((error) => {
3621
+ if (error.name !== "AbortError") {
3622
+ this.dispatchToListeners("error", error);
3623
+ }
3624
+ });
3625
+ this.subscriptions.set(channel, {
3626
+ command,
3627
+ controller,
3628
+ isPattern: false
3629
+ });
3630
+ }
3631
+ subscribeToPattern(pattern) {
3632
+ const controller = new AbortController();
3633
+ const command = new PSubscribeCommand([pattern], {
3634
+ streamOptions: {
3635
+ signal: controller.signal,
3636
+ onMessage: (data) => this.handleMessage(data, true)
3637
+ }
3638
+ });
3639
+ command.exec(this.client).catch((error) => {
3640
+ if (error.name !== "AbortError") {
3641
+ this.dispatchToListeners("error", error);
3642
+ }
3643
+ });
3644
+ this.subscriptions.set(pattern, {
3645
+ command,
3646
+ controller,
3647
+ isPattern: true
3648
+ });
3649
+ }
3650
+ handleMessage(data, isPattern) {
3651
+ const messageData = data.replace(/^data:\s*/, "");
3652
+ const firstCommaIndex = messageData.indexOf(",");
3653
+ const secondCommaIndex = messageData.indexOf(",", firstCommaIndex + 1);
3654
+ const thirdCommaIndex = isPattern ? messageData.indexOf(",", secondCommaIndex + 1) : -1;
3655
+ if (firstCommaIndex !== -1 && secondCommaIndex !== -1) {
3656
+ const type = messageData.slice(0, firstCommaIndex);
3657
+ if (isPattern && type === "pmessage" && thirdCommaIndex !== -1) {
3658
+ const pattern = messageData.slice(firstCommaIndex + 1, secondCommaIndex);
3659
+ const channel = messageData.slice(secondCommaIndex + 1, thirdCommaIndex);
3660
+ const messageStr = messageData.slice(thirdCommaIndex + 1);
3661
+ try {
3662
+ const message = this.opts?.automaticDeserialization === false ? messageStr : JSON.parse(messageStr);
3663
+ this.dispatchToListeners("pmessage", { pattern, channel, message });
3664
+ this.dispatchToListeners(`pmessage:${pattern}`, { pattern, channel, message });
3665
+ } catch (error) {
3666
+ this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
3667
+ }
3668
+ } else {
3669
+ const channel = messageData.slice(firstCommaIndex + 1, secondCommaIndex);
3670
+ const messageStr = messageData.slice(secondCommaIndex + 1);
3671
+ try {
3672
+ if (type === "subscribe" || type === "psubscribe" || type === "unsubscribe" || type === "punsubscribe") {
3673
+ const count = Number.parseInt(messageStr);
3674
+ this.dispatchToListeners(type, count);
3675
+ } else {
3676
+ const message = this.opts?.automaticDeserialization === false ? messageStr : parseWithTryCatch(messageStr);
3677
+ this.dispatchToListeners(type, { channel, message });
3678
+ this.dispatchToListeners(`${type}:${channel}`, { channel, message });
3679
+ }
3680
+ } catch (error) {
3681
+ this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
3682
+ }
3683
+ }
3684
+ }
3685
+ }
3686
+ dispatchToListeners(type, data) {
3687
+ const listeners = this.listeners.get(type);
3688
+ if (listeners) {
3689
+ for (const listener of listeners) {
3690
+ listener(data);
3691
+ }
3692
+ }
3693
+ }
3694
+ on(type, listener) {
3695
+ if (!this.listeners.has(type)) {
3696
+ this.listeners.set(type, /* @__PURE__ */ new Set());
3697
+ }
3698
+ this.listeners.get(type)?.add(listener);
3699
+ }
3700
+ removeAllListeners() {
3701
+ this.listeners.clear();
3702
+ }
3703
+ async unsubscribe(channels) {
3704
+ if (channels) {
3705
+ for (const channel of channels) {
3706
+ const subscription = this.subscriptions.get(channel);
3707
+ if (subscription) {
3708
+ try {
3709
+ subscription.controller.abort();
3710
+ } catch {
3711
+ }
3712
+ this.subscriptions.delete(channel);
3713
+ }
3714
+ }
3715
+ } else {
3716
+ for (const subscription of this.subscriptions.values()) {
3717
+ try {
3718
+ subscription.controller.abort();
3719
+ } catch {
3720
+ }
3721
+ }
3722
+ this.subscriptions.clear();
3723
+ this.removeAllListeners();
3724
+ }
3725
+ }
3726
+ getSubscribedChannels() {
3727
+ return [...this.subscriptions.keys()];
3728
+ }
3729
+ };
3730
+ var SubscribeCommand = class extends Command {
3731
+ constructor(cmd, opts) {
3732
+ const sseHeaders = {
3733
+ Accept: "text/event-stream",
3734
+ "Cache-Control": "no-cache",
3735
+ Connection: "keep-alive"
3736
+ };
3737
+ super([], {
3738
+ ...opts,
3739
+ headers: sseHeaders,
3740
+ path: ["subscribe", ...cmd],
3741
+ streamOptions: {
3742
+ isStreaming: true,
3743
+ onMessage: opts?.streamOptions?.onMessage,
3744
+ signal: opts?.streamOptions?.signal
3745
+ }
3746
+ });
3747
+ }
3748
+ };
3749
+ var parseWithTryCatch = (str) => {
3750
+ try {
3751
+ return JSON.parse(str);
3752
+ } catch {
3753
+ return str;
3754
+ }
3755
+ };
3756
+
3757
+ // pkg/script.ts
3758
+ import { subtle } from "uncrypto";
3759
+ var Script = class {
3760
+ script;
3761
+ /**
3762
+ * @deprecated This property is initialized to an empty string and will be set in the init method
3763
+ * asynchronously. Do not use this property immidiately after the constructor.
3764
+ *
3765
+ * This property is only exposed for backwards compatibility and will be removed in the
3766
+ * future major release.
3767
+ */
3768
+ sha1;
3769
+ redis;
3770
+ constructor(redis, script) {
3771
+ this.redis = redis;
3772
+ this.script = script;
3773
+ this.sha1 = "";
3774
+ void this.init(script);
3775
+ }
3776
+ /**
3777
+ * Initialize the script by computing its SHA-1 hash.
3778
+ */
3779
+ async init(script) {
3780
+ if (this.sha1) return;
3781
+ this.sha1 = await this.digest(script);
3782
+ }
3783
+ /**
3784
+ * Send an `EVAL` command to redis.
3785
+ */
3786
+ async eval(keys, args) {
3787
+ await this.init(this.script);
3788
+ return await this.redis.eval(this.script, keys, args);
3789
+ }
3790
+ /**
3791
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
3792
+ */
3793
+ async evalsha(keys, args) {
3794
+ await this.init(this.script);
3795
+ return await this.redis.evalsha(this.sha1, keys, args);
3796
+ }
3797
+ /**
3798
+ * Optimistically try to run `EVALSHA` first.
3799
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
3800
+ *
3801
+ * Following calls will be able to use the cached script
3802
+ */
3803
+ async exec(keys, args) {
3804
+ await this.init(this.script);
3805
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (error) => {
3806
+ if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
3807
+ return await this.redis.eval(this.script, keys, args);
3808
+ }
3809
+ throw error;
3810
+ });
3811
+ return res;
3812
+ }
3813
+ /**
3814
+ * Compute the sha1 hash of the script and return its hex representation.
3815
+ */
3816
+ async digest(s) {
3817
+ const data = new TextEncoder().encode(s);
3818
+ const hashBuffer = await subtle.digest("SHA-1", data);
3819
+ const hashArray = [...new Uint8Array(hashBuffer)];
3820
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
3821
+ }
3822
+ };
3823
+
3824
+ // pkg/scriptRo.ts
3825
+ import { subtle as subtle2 } from "uncrypto";
3826
+ var ScriptRO = class {
3827
+ script;
3828
+ /**
3829
+ * @deprecated This property is initialized to an empty string and will be set in the init method
3830
+ * asynchronously. Do not use this property immidiately after the constructor.
3831
+ *
3832
+ * This property is only exposed for backwards compatibility and will be removed in the
3833
+ * future major release.
3834
+ */
3835
+ sha1;
3836
+ redis;
3837
+ constructor(redis, script) {
3838
+ this.redis = redis;
3839
+ this.sha1 = "";
3840
+ this.script = script;
3841
+ void this.init(script);
3842
+ }
3843
+ async init(script) {
3844
+ if (this.sha1) return;
3845
+ this.sha1 = await this.digest(script);
3846
+ }
3847
+ /**
3848
+ * Send an `EVAL_RO` command to redis.
3849
+ */
3850
+ async evalRo(keys, args) {
3851
+ await this.init(this.script);
3852
+ return await this.redis.evalRo(this.script, keys, args);
3853
+ }
3854
+ /**
3855
+ * Calculates the sha1 hash of the script and then calls `EVALSHA_RO`.
3856
+ */
3857
+ async evalshaRo(keys, args) {
3858
+ await this.init(this.script);
3859
+ return await this.redis.evalshaRo(this.sha1, keys, args);
3860
+ }
3861
+ /**
3862
+ * Optimistically try to run `EVALSHA_RO` first.
3863
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL_RO`.
3864
+ *
3865
+ * Following calls will be able to use the cached script
3866
+ */
3867
+ async exec(keys, args) {
3868
+ await this.init(this.script);
3869
+ const res = await this.redis.evalshaRo(this.sha1, keys, args).catch(async (error) => {
3870
+ if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
3871
+ return await this.redis.evalRo(this.script, keys, args);
3872
+ }
3873
+ throw error;
3874
+ });
3875
+ return res;
3876
+ }
3877
+ /**
3878
+ * Compute the sha1 hash of the script and return its hex representation.
3879
+ */
3880
+ async digest(s) {
3881
+ const data = new TextEncoder().encode(s);
3882
+ const hashBuffer = await subtle2.digest("SHA-1", data);
3883
+ const hashArray = [...new Uint8Array(hashBuffer)];
3884
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
3885
+ }
3886
+ };
3887
+
3888
+ // pkg/redis.ts
3889
+ var Redis = class {
3890
+ client;
3891
+ opts;
3892
+ enableTelemetry;
3893
+ enableAutoPipelining;
3894
+ /**
3895
+ * Create a new redis client
3896
+ *
3897
+ * @example
3898
+ * ```typescript
3899
+ * const redis = new Redis({
3900
+ * url: "<UPSTASH_REDIS_REST_URL>",
3901
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
3902
+ * });
3903
+ * ```
3904
+ */
3905
+ constructor(client, opts) {
3906
+ this.client = client;
3907
+ this.opts = opts;
3908
+ this.enableTelemetry = opts?.enableTelemetry ?? true;
3909
+ if (opts?.readYourWrites === false) {
3910
+ this.client.readYourWrites = false;
3911
+ }
3912
+ this.enableAutoPipelining = opts?.enableAutoPipelining ?? true;
3913
+ }
3914
+ get readYourWritesSyncToken() {
3915
+ return this.client.upstashSyncToken;
3916
+ }
3917
+ set readYourWritesSyncToken(session) {
3918
+ this.client.upstashSyncToken = session;
3919
+ }
3920
+ get json() {
3921
+ return {
3922
+ /**
3923
+ * @see https://redis.io/commands/json.arrappend
3924
+ */
3925
+ arrappend: (...args) => new JsonArrAppendCommand(args, this.opts).exec(this.client),
3926
+ /**
3927
+ * @see https://redis.io/commands/json.arrindex
3928
+ */
3929
+ arrindex: (...args) => new JsonArrIndexCommand(args, this.opts).exec(this.client),
3930
+ /**
3931
+ * @see https://redis.io/commands/json.arrinsert
3932
+ */
3933
+ arrinsert: (...args) => new JsonArrInsertCommand(args, this.opts).exec(this.client),
3934
+ /**
3935
+ * @see https://redis.io/commands/json.arrlen
3936
+ */
3937
+ arrlen: (...args) => new JsonArrLenCommand(args, this.opts).exec(this.client),
3938
+ /**
3939
+ * @see https://redis.io/commands/json.arrpop
3940
+ */
3941
+ arrpop: (...args) => new JsonArrPopCommand(args, this.opts).exec(this.client),
3942
+ /**
3943
+ * @see https://redis.io/commands/json.arrtrim
3944
+ */
3945
+ arrtrim: (...args) => new JsonArrTrimCommand(args, this.opts).exec(this.client),
3946
+ /**
3947
+ * @see https://redis.io/commands/json.clear
3948
+ */
3949
+ clear: (...args) => new JsonClearCommand(args, this.opts).exec(this.client),
3950
+ /**
3951
+ * @see https://redis.io/commands/json.del
3952
+ */
3953
+ del: (...args) => new JsonDelCommand(args, this.opts).exec(this.client),
3954
+ /**
3955
+ * @see https://redis.io/commands/json.forget
3956
+ */
3957
+ forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
3958
+ /**
3959
+ * @see https://redis.io/commands/json.get
3960
+ */
3961
+ get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
3962
+ /**
3963
+ * @see https://redis.io/commands/json.merge
3964
+ */
3965
+ merge: (...args) => new JsonMergeCommand(args, this.opts).exec(this.client),
3966
+ /**
3967
+ * @see https://redis.io/commands/json.mget
3968
+ */
3969
+ mget: (...args) => new JsonMGetCommand(args, this.opts).exec(this.client),
3970
+ /**
3971
+ * @see https://redis.io/commands/json.mset
3972
+ */
3973
+ mset: (...args) => new JsonMSetCommand(args, this.opts).exec(this.client),
3974
+ /**
3975
+ * @see https://redis.io/commands/json.numincrby
3976
+ */
3977
+ numincrby: (...args) => new JsonNumIncrByCommand(args, this.opts).exec(this.client),
3978
+ /**
3979
+ * @see https://redis.io/commands/json.nummultby
3980
+ */
3981
+ nummultby: (...args) => new JsonNumMultByCommand(args, this.opts).exec(this.client),
3982
+ /**
3983
+ * @see https://redis.io/commands/json.objkeys
3984
+ */
3985
+ objkeys: (...args) => new JsonObjKeysCommand(args, this.opts).exec(this.client),
3986
+ /**
3987
+ * @see https://redis.io/commands/json.objlen
3988
+ */
3989
+ objlen: (...args) => new JsonObjLenCommand(args, this.opts).exec(this.client),
3990
+ /**
3991
+ * @see https://redis.io/commands/json.resp
3992
+ */
3993
+ resp: (...args) => new JsonRespCommand(args, this.opts).exec(this.client),
3994
+ /**
3995
+ * @see https://redis.io/commands/json.set
3996
+ */
3997
+ set: (...args) => new JsonSetCommand(args, this.opts).exec(this.client),
3998
+ /**
3999
+ * @see https://redis.io/commands/json.strappend
4000
+ */
4001
+ strappend: (...args) => new JsonStrAppendCommand(args, this.opts).exec(this.client),
4002
+ /**
4003
+ * @see https://redis.io/commands/json.strlen
4004
+ */
4005
+ strlen: (...args) => new JsonStrLenCommand(args, this.opts).exec(this.client),
4006
+ /**
4007
+ * @see https://redis.io/commands/json.toggle
4008
+ */
4009
+ toggle: (...args) => new JsonToggleCommand(args, this.opts).exec(this.client),
4010
+ /**
4011
+ * @see https://redis.io/commands/json.type
4012
+ */
4013
+ type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
4014
+ };
4015
+ }
4016
+ get functions() {
4017
+ return {
4018
+ /**
4019
+ * @see https://redis.io/docs/latest/commands/function-load/
4020
+ */
4021
+ load: (...args) => new FunctionLoadCommand(args, this.opts).exec(this.client),
4022
+ /**
4023
+ * @see https://redis.io/docs/latest/commands/function-list/
4024
+ */
4025
+ list: (...args) => new FunctionListCommand(args, this.opts).exec(this.client),
4026
+ /**
4027
+ * @see https://redis.io/docs/latest/commands/function-delete/
4028
+ */
4029
+ delete: (...args) => new FunctionDeleteCommand(args, this.opts).exec(this.client),
4030
+ /**
4031
+ * @see https://redis.io/docs/latest/commands/function-flush/
4032
+ */
4033
+ flush: () => new FunctionFlushCommand(this.opts).exec(this.client),
4034
+ /**
4035
+ * @see https://redis.io/docs/latest/commands/function-stats/
4036
+ *
4037
+ * Note: `running_script` field is not supported and therefore not included in the type.
4038
+ */
4039
+ stats: () => new FunctionStatsCommand(this.opts).exec(this.client),
4040
+ /**
4041
+ * @see https://redis.io/docs/latest/commands/fcall/
4042
+ */
4043
+ call: (...args) => new FCallCommand(args, this.opts).exec(this.client),
4044
+ /**
4045
+ * @see https://redis.io/docs/latest/commands/fcall_ro/
4046
+ */
4047
+ callRo: (...args) => new FCallRoCommand(args, this.opts).exec(this.client)
4048
+ };
4049
+ }
4050
+ /**
4051
+ * Wrap a new middleware around the HTTP client.
4052
+ */
4053
+ use = (middleware) => {
4054
+ const makeRequest = this.client.request.bind(this.client);
4055
+ this.client.request = (req) => middleware(req, makeRequest);
4056
+ };
4057
+ /**
4058
+ * Technically this is not private, we can hide it from intellisense by doing this
4059
+ */
4060
+ addTelemetry = (telemetry) => {
4061
+ if (!this.enableTelemetry) {
4062
+ return;
4063
+ }
4064
+ try {
4065
+ this.client.mergeTelemetry(telemetry);
4066
+ } catch {
4067
+ }
4068
+ };
4069
+ /**
4070
+ * Creates a new script.
4071
+ *
4072
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
4073
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
4074
+ * the entire script. Afterwards, the script is cached on the server.
4075
+ *
4076
+ * @param script - The script to create
4077
+ * @param opts - Optional options to pass to the script `{ readonly?: boolean }`
4078
+ * @returns A new script
4079
+ *
4080
+ * @example
4081
+ * ```ts
4082
+ * const redis = new Redis({...})
4083
+ *
4084
+ * const script = redis.createScript<string>("return ARGV[1];")
4085
+ * const arg1 = await script.eval([], ["Hello World"])
4086
+ * expect(arg1, "Hello World")
4087
+ * ```
4088
+ * @example
4089
+ * ```ts
4090
+ * const redis = new Redis({...})
4091
+ *
4092
+ * const script = redis.createScript<string>("return ARGV[1];", { readonly: true })
4093
+ * const arg1 = await script.evalRo([], ["Hello World"])
4094
+ * expect(arg1, "Hello World")
4095
+ * ```
4096
+ */
4097
+ createScript(script, opts) {
4098
+ return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
4099
+ }
4100
+ /**
4101
+ * Create a new pipeline that allows you to send requests in bulk.
4102
+ *
4103
+ * @see {@link Pipeline}
4104
+ */
4105
+ pipeline = () => new Pipeline({
4106
+ client: this.client,
4107
+ commandOptions: this.opts,
4108
+ multiExec: false
4109
+ });
4110
+ autoPipeline = () => {
4111
+ return createAutoPipelineProxy(this);
4112
+ };
4113
+ /**
4114
+ * Create a new transaction to allow executing multiple steps atomically.
4115
+ *
4116
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
4117
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
4118
+ * guarantees that the commands are executed as a single isolated operation.
4119
+ *
4120
+ * @see {@link Pipeline}
4121
+ */
4122
+ multi = () => new Pipeline({
4123
+ client: this.client,
4124
+ commandOptions: this.opts,
4125
+ multiExec: true
4126
+ });
4127
+ /**
4128
+ * Returns an instance that can be used to execute `BITFIELD` commands on one key.
4129
+ *
4130
+ * @example
4131
+ * ```typescript
4132
+ * redis.set("mykey", 0);
4133
+ * const result = await redis.bitfield("mykey")
4134
+ * .set("u4", 0, 16)
4135
+ * .incr("u4", "#1", 1)
4136
+ * .exec();
4137
+ * console.log(result); // [0, 1]
4138
+ * ```
4139
+ *
4140
+ * @see https://redis.io/commands/bitfield
4141
+ */
4142
+ bitfield = (...args) => new BitFieldCommand(args, this.client, this.opts);
4143
+ /**
4144
+ * @see https://redis.io/commands/append
4145
+ */
4146
+ append = (...args) => new AppendCommand(args, this.opts).exec(this.client);
4147
+ /**
4148
+ * @see https://redis.io/commands/bitcount
4149
+ */
4150
+ bitcount = (...args) => new BitCountCommand(args, this.opts).exec(this.client);
4151
+ /**
4152
+ * @see https://redis.io/commands/bitop
4153
+ */
4154
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => new BitOpCommand([op, destinationKey, sourceKey, ...sourceKeys], this.opts).exec(
4155
+ this.client
4156
+ );
4157
+ /**
4158
+ * @see https://redis.io/commands/bitpos
4159
+ */
4160
+ bitpos = (...args) => new BitPosCommand(args, this.opts).exec(this.client);
4161
+ /**
4162
+ * @see https://redis.io/commands/client-setinfo
4163
+ */
4164
+ clientSetinfo = (...args) => new ClientSetInfoCommand(args, this.opts).exec(this.client);
4165
+ /**
4166
+ * @see https://redis.io/commands/copy
4167
+ */
4168
+ copy = (...args) => new CopyCommand(args, this.opts).exec(this.client);
4169
+ /**
4170
+ * @see https://redis.io/commands/dbsize
4171
+ */
4172
+ dbsize = () => new DBSizeCommand(this.opts).exec(this.client);
4173
+ /**
4174
+ * @see https://redis.io/commands/decr
4175
+ */
4176
+ decr = (...args) => new DecrCommand(args, this.opts).exec(this.client);
4177
+ /**
4178
+ * @see https://redis.io/commands/decrby
4179
+ */
4180
+ decrby = (...args) => new DecrByCommand(args, this.opts).exec(this.client);
4181
+ /**
4182
+ * @see https://redis.io/commands/del
4183
+ */
4184
+ del = (...args) => new DelCommand(args, this.opts).exec(this.client);
4185
+ /**
4186
+ * @see https://redis.io/commands/echo
4187
+ */
4188
+ echo = (...args) => new EchoCommand(args, this.opts).exec(this.client);
4189
+ /**
4190
+ * @see https://redis.io/commands/eval_ro
4191
+ */
4192
+ evalRo = (...args) => new EvalROCommand(args, this.opts).exec(this.client);
4193
+ /**
4194
+ * @see https://redis.io/commands/eval
4195
+ */
4196
+ eval = (...args) => new EvalCommand(args, this.opts).exec(this.client);
4197
+ /**
4198
+ * @see https://redis.io/commands/evalsha_ro
4199
+ */
4200
+ evalshaRo = (...args) => new EvalshaROCommand(args, this.opts).exec(this.client);
4201
+ /**
4202
+ * @see https://redis.io/commands/evalsha
4203
+ */
4204
+ evalsha = (...args) => new EvalshaCommand(args, this.opts).exec(this.client);
4205
+ /**
4206
+ * Generic method to execute any Redis command.
4207
+ */
4208
+ exec = (args) => new ExecCommand(args, this.opts).exec(this.client);
4209
+ /**
4210
+ * @see https://redis.io/commands/exists
4211
+ */
4212
+ exists = (...args) => new ExistsCommand(args, this.opts).exec(this.client);
4213
+ /**
4214
+ * @see https://redis.io/commands/expire
4215
+ */
4216
+ expire = (...args) => new ExpireCommand(args, this.opts).exec(this.client);
4217
+ /**
4218
+ * @see https://redis.io/commands/expireat
4219
+ */
4220
+ expireat = (...args) => new ExpireAtCommand(args, this.opts).exec(this.client);
4221
+ /**
4222
+ * @see https://redis.io/commands/flushall
4223
+ */
4224
+ flushall = (args) => new FlushAllCommand(args, this.opts).exec(this.client);
4225
+ /**
4226
+ * @see https://redis.io/commands/flushdb
4227
+ */
4228
+ flushdb = (...args) => new FlushDBCommand(args, this.opts).exec(this.client);
4229
+ /**
4230
+ * @see https://redis.io/commands/geoadd
4231
+ */
4232
+ geoadd = (...args) => new GeoAddCommand(args, this.opts).exec(this.client);
4233
+ /**
4234
+ * @see https://redis.io/commands/geopos
4235
+ */
4236
+ geopos = (...args) => new GeoPosCommand(args, this.opts).exec(this.client);
4237
+ /**
4238
+ * @see https://redis.io/commands/geodist
4239
+ */
4240
+ geodist = (...args) => new GeoDistCommand(args, this.opts).exec(this.client);
4241
+ /**
4242
+ * @see https://redis.io/commands/geohash
4243
+ */
4244
+ geohash = (...args) => new GeoHashCommand(args, this.opts).exec(this.client);
4245
+ /**
4246
+ * @see https://redis.io/commands/geosearch
4247
+ */
4248
+ geosearch = (...args) => new GeoSearchCommand(args, this.opts).exec(this.client);
4249
+ /**
4250
+ * @see https://redis.io/commands/geosearchstore
4251
+ */
4252
+ geosearchstore = (...args) => new GeoSearchStoreCommand(args, this.opts).exec(this.client);
4253
+ /**
4254
+ * @see https://redis.io/commands/get
4255
+ */
4256
+ get = (...args) => new GetCommand(args, this.opts).exec(this.client);
4257
+ /**
4258
+ * @see https://redis.io/commands/getbit
4259
+ */
4260
+ getbit = (...args) => new GetBitCommand(args, this.opts).exec(this.client);
4261
+ /**
4262
+ * @see https://redis.io/commands/getdel
4263
+ */
4264
+ getdel = (...args) => new GetDelCommand(args, this.opts).exec(this.client);
4265
+ /**
4266
+ * @see https://redis.io/commands/getex
4267
+ */
4268
+ getex = (...args) => new GetExCommand(args, this.opts).exec(this.client);
4269
+ /**
4270
+ * @see https://redis.io/commands/getrange
4271
+ */
4272
+ getrange = (...args) => new GetRangeCommand(args, this.opts).exec(this.client);
4273
+ /**
4274
+ * @see https://redis.io/commands/getset
4275
+ */
4276
+ getset = (key, value) => new GetSetCommand([key, value], this.opts).exec(this.client);
4277
+ /**
4278
+ * @see https://redis.io/commands/hdel
4279
+ */
4280
+ hdel = (...args) => new HDelCommand(args, this.opts).exec(this.client);
4281
+ /**
4282
+ * @see https://redis.io/commands/hexists
4283
+ */
4284
+ hexists = (...args) => new HExistsCommand(args, this.opts).exec(this.client);
4285
+ /**
4286
+ * @see https://redis.io/commands/hexpire
4287
+ */
4288
+ hexpire = (...args) => new HExpireCommand(args, this.opts).exec(this.client);
4289
+ /**
4290
+ * @see https://redis.io/commands/hexpireat
4291
+ */
4292
+ hexpireat = (...args) => new HExpireAtCommand(args, this.opts).exec(this.client);
4293
+ /**
4294
+ * @see https://redis.io/commands/hexpiretime
4295
+ */
4296
+ hexpiretime = (...args) => new HExpireTimeCommand(args, this.opts).exec(this.client);
4297
+ /**
4298
+ * @see https://redis.io/commands/httl
4299
+ */
4300
+ httl = (...args) => new HTtlCommand(args, this.opts).exec(this.client);
4301
+ /**
4302
+ * @see https://redis.io/commands/hpexpire
4303
+ */
4304
+ hpexpire = (...args) => new HPExpireCommand(args, this.opts).exec(this.client);
4305
+ /**
4306
+ * @see https://redis.io/commands/hpexpireat
4307
+ */
4308
+ hpexpireat = (...args) => new HPExpireAtCommand(args, this.opts).exec(this.client);
4309
+ /**
4310
+ * @see https://redis.io/commands/hpexpiretime
4311
+ */
4312
+ hpexpiretime = (...args) => new HPExpireTimeCommand(args, this.opts).exec(this.client);
4313
+ /**
4314
+ * @see https://redis.io/commands/hpttl
4315
+ */
4316
+ hpttl = (...args) => new HPTtlCommand(args, this.opts).exec(this.client);
4317
+ /**
4318
+ * @see https://redis.io/commands/hpersist
4319
+ */
4320
+ hpersist = (...args) => new HPersistCommand(args, this.opts).exec(this.client);
4321
+ /**
4322
+ * @see https://redis.io/commands/hget
4323
+ */
4324
+ hget = (...args) => new HGetCommand(args, this.opts).exec(this.client);
4325
+ /**
4326
+ * @see https://redis.io/commands/hgetall
4327
+ */
4328
+ hgetall = (...args) => new HGetAllCommand(args, this.opts).exec(this.client);
4329
+ /**
4330
+ * @see https://redis.io/commands/hgetdel
4331
+ */
4332
+ hgetdel = (...args) => new HGetDelCommand(args, this.opts).exec(this.client);
4333
+ /**
4334
+ * @see https://redis.io/commands/hgetex
4335
+ */
4336
+ hgetex = (...args) => new HGetExCommand(args, this.opts).exec(this.client);
4337
+ /**
4338
+ * @see https://redis.io/commands/hincrby
4339
+ */
4340
+ hincrby = (...args) => new HIncrByCommand(args, this.opts).exec(this.client);
4341
+ /**
4342
+ * @see https://redis.io/commands/hincrbyfloat
4343
+ */
4344
+ hincrbyfloat = (...args) => new HIncrByFloatCommand(args, this.opts).exec(this.client);
4345
+ /**
4346
+ * @see https://redis.io/commands/hkeys
4347
+ */
4348
+ hkeys = (...args) => new HKeysCommand(args, this.opts).exec(this.client);
4349
+ /**
4350
+ * @see https://redis.io/commands/hlen
4351
+ */
4352
+ hlen = (...args) => new HLenCommand(args, this.opts).exec(this.client);
4353
+ /**
4354
+ * @see https://redis.io/commands/hmget
4355
+ */
4356
+ hmget = (...args) => new HMGetCommand(args, this.opts).exec(this.client);
4357
+ /**
4358
+ * @see https://redis.io/commands/hmset
4359
+ */
4360
+ hmset = (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client);
4361
+ /**
4362
+ * @see https://redis.io/commands/hrandfield
4363
+ */
4364
+ hrandfield = (key, count, withValues) => new HRandFieldCommand([key, count, withValues], this.opts).exec(this.client);
4365
+ /**
4366
+ * @see https://redis.io/commands/hscan
4367
+ */
4368
+ hscan = (...args) => new HScanCommand(args, this.opts).exec(this.client);
4369
+ /**
4370
+ * @see https://redis.io/commands/hset
4371
+ */
4372
+ hset = (key, kv) => new HSetCommand([key, kv], this.opts).exec(this.client);
4373
+ /**
4374
+ * @see https://redis.io/commands/hsetex
4375
+ */
4376
+ hsetex = (...args) => new HSetExCommand(args, this.opts).exec(this.client);
4377
+ /**
4378
+ * @see https://redis.io/commands/hsetnx
4379
+ */
4380
+ hsetnx = (key, field, value) => new HSetNXCommand([key, field, value], this.opts).exec(this.client);
4381
+ /**
4382
+ * @see https://redis.io/commands/hstrlen
4383
+ */
4384
+ hstrlen = (...args) => new HStrLenCommand(args, this.opts).exec(this.client);
4385
+ /**
4386
+ * @see https://redis.io/commands/hvals
4387
+ */
4388
+ hvals = (...args) => new HValsCommand(args, this.opts).exec(this.client);
4389
+ /**
4390
+ * @see https://redis.io/commands/incr
4391
+ */
4392
+ incr = (...args) => new IncrCommand(args, this.opts).exec(this.client);
4393
+ /**
4394
+ * @see https://redis.io/commands/incrby
4395
+ */
4396
+ incrby = (...args) => new IncrByCommand(args, this.opts).exec(this.client);
4397
+ /**
4398
+ * @see https://redis.io/commands/incrbyfloat
4399
+ */
4400
+ incrbyfloat = (...args) => new IncrByFloatCommand(args, this.opts).exec(this.client);
4401
+ /**
4402
+ * @see https://redis.io/commands/keys
4403
+ */
4404
+ keys = (...args) => new KeysCommand(args, this.opts).exec(this.client);
4405
+ /**
4406
+ * @see https://redis.io/commands/lindex
4407
+ */
4408
+ lindex = (...args) => new LIndexCommand(args, this.opts).exec(this.client);
4409
+ /**
4410
+ * @see https://redis.io/commands/linsert
4411
+ */
4412
+ linsert = (key, direction, pivot, value) => new LInsertCommand([key, direction, pivot, value], this.opts).exec(this.client);
4413
+ /**
4414
+ * @see https://redis.io/commands/llen
4415
+ */
4416
+ llen = (...args) => new LLenCommand(args, this.opts).exec(this.client);
4417
+ /**
4418
+ * @see https://redis.io/commands/lmove
4419
+ */
4420
+ lmove = (...args) => new LMoveCommand(args, this.opts).exec(this.client);
4421
+ /**
4422
+ * @see https://redis.io/commands/lpop
4423
+ */
4424
+ lpop = (...args) => new LPopCommand(args, this.opts).exec(this.client);
4425
+ /**
4426
+ * @see https://redis.io/commands/lmpop
4427
+ */
4428
+ lmpop = (...args) => new LmPopCommand(args, this.opts).exec(this.client);
4429
+ /**
4430
+ * @see https://redis.io/commands/lpos
4431
+ */
4432
+ lpos = (...args) => new LPosCommand(args, this.opts).exec(this.client);
4433
+ /**
4434
+ * @see https://redis.io/commands/lpush
4435
+ */
4436
+ lpush = (key, ...elements) => new LPushCommand([key, ...elements], this.opts).exec(this.client);
4437
+ /**
4438
+ * @see https://redis.io/commands/lpushx
4439
+ */
4440
+ lpushx = (key, ...elements) => new LPushXCommand([key, ...elements], this.opts).exec(this.client);
4441
+ /**
4442
+ * @see https://redis.io/commands/lrange
4443
+ */
4444
+ lrange = (...args) => new LRangeCommand(args, this.opts).exec(this.client);
4445
+ /**
4446
+ * @see https://redis.io/commands/lrem
4447
+ */
4448
+ lrem = (key, count, value) => new LRemCommand([key, count, value], this.opts).exec(this.client);
4449
+ /**
4450
+ * @see https://redis.io/commands/lset
4451
+ */
4452
+ lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
4453
+ /**
4454
+ * @see https://redis.io/commands/ltrim
4455
+ */
4456
+ ltrim = (...args) => new LTrimCommand(args, this.opts).exec(this.client);
4457
+ /**
4458
+ * @see https://redis.io/commands/mget
4459
+ */
4460
+ mget = (...args) => new MGetCommand(args, this.opts).exec(this.client);
4461
+ /**
4462
+ * @see https://redis.io/commands/mset
4463
+ */
4464
+ mset = (kv) => new MSetCommand([kv], this.opts).exec(this.client);
4465
+ /**
4466
+ * @see https://redis.io/commands/msetnx
4467
+ */
4468
+ msetnx = (kv) => new MSetNXCommand([kv], this.opts).exec(this.client);
4469
+ /**
4470
+ * @see https://redis.io/commands/persist
4471
+ */
4472
+ persist = (...args) => new PersistCommand(args, this.opts).exec(this.client);
4473
+ /**
4474
+ * @see https://redis.io/commands/pexpire
4475
+ */
4476
+ pexpire = (...args) => new PExpireCommand(args, this.opts).exec(this.client);
4477
+ /**
4478
+ * @see https://redis.io/commands/pexpireat
4479
+ */
4480
+ pexpireat = (...args) => new PExpireAtCommand(args, this.opts).exec(this.client);
4481
+ /**
4482
+ * @see https://redis.io/commands/pfadd
4483
+ */
4484
+ pfadd = (...args) => new PfAddCommand(args, this.opts).exec(this.client);
4485
+ /**
4486
+ * @see https://redis.io/commands/pfcount
4487
+ */
4488
+ pfcount = (...args) => new PfCountCommand(args, this.opts).exec(this.client);
4489
+ /**
4490
+ * @see https://redis.io/commands/pfmerge
4491
+ */
4492
+ pfmerge = (...args) => new PfMergeCommand(args, this.opts).exec(this.client);
4493
+ /**
4494
+ * @see https://redis.io/commands/ping
4495
+ */
4496
+ ping = (args) => new PingCommand(args, this.opts).exec(this.client);
4497
+ /**
4498
+ * @see https://redis.io/commands/psetex
4499
+ */
4500
+ psetex = (key, ttl, value) => new PSetEXCommand([key, ttl, value], this.opts).exec(this.client);
4501
+ /**
4502
+ * @see https://redis.io/commands/psubscribe
4503
+ */
4504
+ psubscribe = (patterns) => {
4505
+ const patternArray = Array.isArray(patterns) ? patterns : [patterns];
4506
+ return new Subscriber(this.client, patternArray, true, this.opts);
4507
+ };
4508
+ /**
4509
+ * @see https://redis.io/commands/pttl
4510
+ */
4511
+ pttl = (...args) => new PTtlCommand(args, this.opts).exec(this.client);
4512
+ /**
4513
+ * @see https://redis.io/commands/publish
4514
+ */
4515
+ publish = (...args) => new PublishCommand(args, this.opts).exec(this.client);
4516
+ /**
4517
+ * @see https://redis.io/commands/randomkey
4518
+ */
4519
+ randomkey = () => new RandomKeyCommand().exec(this.client);
4520
+ /**
4521
+ * @see https://redis.io/commands/rename
4522
+ */
4523
+ rename = (...args) => new RenameCommand(args, this.opts).exec(this.client);
4524
+ /**
4525
+ * @see https://redis.io/commands/renamenx
4526
+ */
4527
+ renamenx = (...args) => new RenameNXCommand(args, this.opts).exec(this.client);
4528
+ /**
4529
+ * @see https://redis.io/commands/rpop
4530
+ */
4531
+ rpop = (...args) => new RPopCommand(args, this.opts).exec(this.client);
4532
+ /**
4533
+ * @see https://redis.io/commands/rpush
4534
+ */
4535
+ rpush = (key, ...elements) => new RPushCommand([key, ...elements], this.opts).exec(this.client);
4536
+ /**
4537
+ * @see https://redis.io/commands/rpushx
4538
+ */
4539
+ rpushx = (key, ...elements) => new RPushXCommand([key, ...elements], this.opts).exec(this.client);
4540
+ /**
4541
+ * @see https://redis.io/commands/sadd
4542
+ */
4543
+ sadd = (key, member, ...members) => new SAddCommand([key, member, ...members], this.opts).exec(this.client);
4544
+ scan(cursor, opts) {
4545
+ return new ScanCommand([cursor, opts], this.opts).exec(this.client);
4546
+ }
4547
+ /**
4548
+ * @see https://redis.io/commands/scard
4549
+ */
4550
+ scard = (...args) => new SCardCommand(args, this.opts).exec(this.client);
4551
+ /**
4552
+ * @see https://redis.io/commands/script-exists
4553
+ */
4554
+ scriptExists = (...args) => new ScriptExistsCommand(args, this.opts).exec(this.client);
4555
+ /**
4556
+ * @see https://redis.io/commands/script-flush
4557
+ */
4558
+ scriptFlush = (...args) => new ScriptFlushCommand(args, this.opts).exec(this.client);
4559
+ /**
4560
+ * @see https://redis.io/commands/script-load
4561
+ */
4562
+ scriptLoad = (...args) => new ScriptLoadCommand(args, this.opts).exec(this.client);
4563
+ /**
4564
+ * @see https://redis.io/commands/sdiff
4565
+ */
4566
+ sdiff = (...args) => new SDiffCommand(args, this.opts).exec(this.client);
4567
+ /**
4568
+ * @see https://redis.io/commands/sdiffstore
4569
+ */
4570
+ sdiffstore = (...args) => new SDiffStoreCommand(args, this.opts).exec(this.client);
4571
+ /**
4572
+ * @see https://redis.io/commands/set
4573
+ */
4574
+ set = (key, value, opts) => new SetCommand([key, value, opts], this.opts).exec(this.client);
4575
+ /**
4576
+ * @see https://redis.io/commands/setbit
4577
+ */
4578
+ setbit = (...args) => new SetBitCommand(args, this.opts).exec(this.client);
4579
+ /**
4580
+ * @see https://redis.io/commands/setex
4581
+ */
4582
+ setex = (key, ttl, value) => new SetExCommand([key, ttl, value], this.opts).exec(this.client);
4583
+ /**
4584
+ * @see https://redis.io/commands/setnx
4585
+ */
4586
+ setnx = (key, value) => new SetNxCommand([key, value], this.opts).exec(this.client);
4587
+ /**
4588
+ * @see https://redis.io/commands/setrange
4589
+ */
4590
+ setrange = (...args) => new SetRangeCommand(args, this.opts).exec(this.client);
4591
+ /**
4592
+ * @see https://redis.io/commands/sinter
4593
+ */
4594
+ sinter = (...args) => new SInterCommand(args, this.opts).exec(this.client);
4595
+ /**
4596
+ * @see https://redis.io/commands/sinterstore
4597
+ */
4598
+ sinterstore = (...args) => new SInterStoreCommand(args, this.opts).exec(this.client);
4599
+ /**
4600
+ * @see https://redis.io/commands/sismember
4601
+ */
4602
+ sismember = (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client);
4603
+ /**
4604
+ * @see https://redis.io/commands/smismember
4605
+ */
4606
+ smismember = (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(this.client);
4607
+ /**
4608
+ * @see https://redis.io/commands/smembers
4609
+ */
4610
+ smembers = (...args) => new SMembersCommand(args, this.opts).exec(this.client);
4611
+ /**
4612
+ * @see https://redis.io/commands/smove
4613
+ */
4614
+ smove = (source, destination, member) => new SMoveCommand([source, destination, member], this.opts).exec(this.client);
4615
+ /**
4616
+ * @see https://redis.io/commands/spop
4617
+ */
4618
+ spop = (...args) => new SPopCommand(args, this.opts).exec(this.client);
4619
+ /**
4620
+ * @see https://redis.io/commands/srandmember
4621
+ */
4622
+ srandmember = (...args) => new SRandMemberCommand(args, this.opts).exec(this.client);
4623
+ /**
4624
+ * @see https://redis.io/commands/srem
4625
+ */
4626
+ srem = (key, ...members) => new SRemCommand([key, ...members], this.opts).exec(this.client);
4627
+ /**
4628
+ * @see https://redis.io/commands/sscan
4629
+ */
4630
+ sscan = (...args) => new SScanCommand(args, this.opts).exec(this.client);
4631
+ /**
4632
+ * @see https://redis.io/commands/strlen
4633
+ */
4634
+ strlen = (...args) => new StrLenCommand(args, this.opts).exec(this.client);
4635
+ /**
4636
+ * @see https://redis.io/commands/subscribe
4637
+ */
4638
+ subscribe = (channels) => {
4639
+ const channelArray = Array.isArray(channels) ? channels : [channels];
4640
+ return new Subscriber(this.client, channelArray, false, this.opts);
4641
+ };
4642
+ /**
4643
+ * @see https://redis.io/commands/sunion
4644
+ */
4645
+ sunion = (...args) => new SUnionCommand(args, this.opts).exec(this.client);
4646
+ /**
4647
+ * @see https://redis.io/commands/sunionstore
4648
+ */
4649
+ sunionstore = (...args) => new SUnionStoreCommand(args, this.opts).exec(this.client);
4650
+ /**
4651
+ * @see https://redis.io/commands/time
4652
+ */
4653
+ time = () => new TimeCommand().exec(this.client);
4654
+ /**
4655
+ * @see https://redis.io/commands/touch
4656
+ */
4657
+ touch = (...args) => new TouchCommand(args, this.opts).exec(this.client);
4658
+ /**
4659
+ * @see https://redis.io/commands/ttl
4660
+ */
4661
+ ttl = (...args) => new TtlCommand(args, this.opts).exec(this.client);
4662
+ /**
4663
+ * @see https://redis.io/commands/type
4664
+ */
4665
+ type = (...args) => new TypeCommand(args, this.opts).exec(this.client);
4666
+ /**
4667
+ * @see https://redis.io/commands/unlink
4668
+ */
4669
+ unlink = (...args) => new UnlinkCommand(args, this.opts).exec(this.client);
4670
+ /**
4671
+ * @see https://redis.io/commands/xadd
4672
+ */
4673
+ xadd = (...args) => new XAddCommand(args, this.opts).exec(this.client);
4674
+ /**
4675
+ * @see https://redis.io/commands/xack
4676
+ */
4677
+ xack = (...args) => new XAckCommand(args, this.opts).exec(this.client);
4678
+ /**
4679
+ * @see https://redis.io/commands/xackdel
4680
+ */
4681
+ xackdel = (...args) => new XAckDelCommand(args, this.opts).exec(this.client);
4682
+ /**
4683
+ * @see https://redis.io/commands/xdel
4684
+ */
4685
+ xdel = (...args) => new XDelCommand(args, this.opts).exec(this.client);
4686
+ /**
4687
+ * @see https://redis.io/commands/xdelex
4688
+ */
4689
+ xdelex = (...args) => new XDelExCommand(args, this.opts).exec(this.client);
4690
+ /**
4691
+ * @see https://redis.io/commands/xgroup
4692
+ */
4693
+ xgroup = (...args) => new XGroupCommand(args, this.opts).exec(this.client);
4694
+ /**
4695
+ * @see https://redis.io/commands/xread
4696
+ */
4697
+ xread = (...args) => new XReadCommand(args, this.opts).exec(this.client);
4698
+ /**
4699
+ * @see https://redis.io/commands/xreadgroup
4700
+ */
4701
+ xreadgroup = (...args) => new XReadGroupCommand(args, this.opts).exec(this.client);
4702
+ /**
4703
+ * @see https://redis.io/commands/xinfo
4704
+ */
4705
+ xinfo = (...args) => new XInfoCommand(args, this.opts).exec(this.client);
4706
+ /**
4707
+ * @see https://redis.io/commands/xlen
4708
+ */
4709
+ xlen = (...args) => new XLenCommand(args, this.opts).exec(this.client);
4710
+ /**
4711
+ * @see https://redis.io/commands/xpending
4712
+ */
4713
+ xpending = (...args) => new XPendingCommand(args, this.opts).exec(this.client);
4714
+ /**
4715
+ * @see https://redis.io/commands/xclaim
4716
+ */
4717
+ xclaim = (...args) => new XClaimCommand(args, this.opts).exec(this.client);
4718
+ /**
4719
+ * @see https://redis.io/commands/xautoclaim
4720
+ */
4721
+ xautoclaim = (...args) => new XAutoClaim(args, this.opts).exec(this.client);
4722
+ /**
4723
+ * @see https://redis.io/commands/xtrim
4724
+ */
4725
+ xtrim = (...args) => new XTrimCommand(args, this.opts).exec(this.client);
4726
+ /**
4727
+ * @see https://redis.io/commands/xrange
4728
+ */
4729
+ xrange = (...args) => new XRangeCommand(args, this.opts).exec(this.client);
4730
+ /**
4731
+ * @see https://redis.io/commands/xrevrange
4732
+ */
4733
+ xrevrange = (...args) => new XRevRangeCommand(args, this.opts).exec(this.client);
4734
+ /**
4735
+ * @see https://redis.io/commands/zadd
4736
+ */
4737
+ zadd = (...args) => {
4738
+ if ("score" in args[1]) {
4739
+ return new ZAddCommand([args[0], args[1], ...args.slice(2)], this.opts).exec(
4740
+ this.client
4741
+ );
4742
+ }
4743
+ return new ZAddCommand(
4744
+ [args[0], args[1], ...args.slice(2)],
4745
+ this.opts
4746
+ ).exec(this.client);
4747
+ };
4748
+ /**
4749
+ * @see https://redis.io/commands/zcard
4750
+ */
4751
+ zcard = (...args) => new ZCardCommand(args, this.opts).exec(this.client);
4752
+ /**
4753
+ * @see https://redis.io/commands/zcount
4754
+ */
4755
+ zcount = (...args) => new ZCountCommand(args, this.opts).exec(this.client);
4756
+ /**
4757
+ * @see https://redis.io/commands/zdiffstore
4758
+ */
4759
+ zdiffstore = (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client);
4760
+ /**
4761
+ * @see https://redis.io/commands/zincrby
4762
+ */
4763
+ zincrby = (key, increment, member) => new ZIncrByCommand([key, increment, member], this.opts).exec(this.client);
4764
+ /**
4765
+ * @see https://redis.io/commands/zinterstore
4766
+ */
4767
+ zinterstore = (...args) => new ZInterStoreCommand(args, this.opts).exec(this.client);
4768
+ /**
4769
+ * @see https://redis.io/commands/zlexcount
4770
+ */
4771
+ zlexcount = (...args) => new ZLexCountCommand(args, this.opts).exec(this.client);
4772
+ /**
4773
+ * @see https://redis.io/commands/zmscore
4774
+ */
4775
+ zmscore = (...args) => new ZMScoreCommand(args, this.opts).exec(this.client);
4776
+ /**
4777
+ * @see https://redis.io/commands/zpopmax
4778
+ */
4779
+ zpopmax = (...args) => new ZPopMaxCommand(args, this.opts).exec(this.client);
4780
+ /**
4781
+ * @see https://redis.io/commands/zpopmin
4782
+ */
4783
+ zpopmin = (...args) => new ZPopMinCommand(args, this.opts).exec(this.client);
4784
+ /**
4785
+ * @see https://redis.io/commands/zrange
4786
+ */
4787
+ zrange = (...args) => new ZRangeCommand(args, this.opts).exec(this.client);
4788
+ /**
4789
+ * @see https://redis.io/commands/zrank
4790
+ */
4791
+ zrank = (key, member) => new ZRankCommand([key, member], this.opts).exec(this.client);
4792
+ /**
4793
+ * @see https://redis.io/commands/zrem
4794
+ */
4795
+ zrem = (key, ...members) => new ZRemCommand([key, ...members], this.opts).exec(this.client);
4796
+ /**
4797
+ * @see https://redis.io/commands/zremrangebylex
4798
+ */
4799
+ zremrangebylex = (...args) => new ZRemRangeByLexCommand(args, this.opts).exec(this.client);
4800
+ /**
4801
+ * @see https://redis.io/commands/zremrangebyrank
4802
+ */
4803
+ zremrangebyrank = (...args) => new ZRemRangeByRankCommand(args, this.opts).exec(this.client);
4804
+ /**
4805
+ * @see https://redis.io/commands/zremrangebyscore
4806
+ */
4807
+ zremrangebyscore = (...args) => new ZRemRangeByScoreCommand(args, this.opts).exec(this.client);
4808
+ /**
4809
+ * @see https://redis.io/commands/zrevrank
4810
+ */
4811
+ zrevrank = (key, member) => new ZRevRankCommand([key, member], this.opts).exec(this.client);
4812
+ /**
4813
+ * @see https://redis.io/commands/zscan
4814
+ */
4815
+ zscan = (...args) => new ZScanCommand(args, this.opts).exec(this.client);
4816
+ /**
4817
+ * @see https://redis.io/commands/zscore
4818
+ */
4819
+ zscore = (key, member) => new ZScoreCommand([key, member], this.opts).exec(this.client);
4820
+ /**
4821
+ * @see https://redis.io/commands/zunion
4822
+ */
4823
+ zunion = (...args) => new ZUnionCommand(args, this.opts).exec(this.client);
4824
+ /**
4825
+ * @see https://redis.io/commands/zunionstore
4826
+ */
4827
+ zunionstore = (...args) => new ZUnionStoreCommand(args, this.opts).exec(this.client);
4828
+ };
4829
+
4830
+ // version.ts
4831
+ var VERSION = "v1.30.2";
4832
+
4833
+ export {
4834
+ error_exports,
4835
+ HttpClient,
4836
+ Redis,
4837
+ VERSION
4838
+ };