@upstash/redis 0.0.0-ci.c00b02de3221a40eb48a9e0e9fecd434abda4dc2-20240704001524 → 0.0.0-ci.c2204f830cf3ca85c9f85a7dc63bd93a0e228f4b-20250403110828

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