@upstash/redis 0.0.0-ci.f5cad9e7bda3d77569d9df207b4e1565f75d6154 → 0.0.0-ci.f725f60c40a2b7f0e25dd9bf83a931c24624cdf6-20260123181037

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