@upstash/redis 0.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fastly.js ADDED
@@ -0,0 +1,3085 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // platforms/fastly.ts
21
+ var fastly_exports = {};
22
+ __export(fastly_exports, {
23
+ Redis: () => Redis2
24
+ });
25
+ module.exports = __toCommonJS(fastly_exports);
26
+
27
+ // pkg/error.ts
28
+ var UpstashError = class extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = "UpstashError";
32
+ }
33
+ };
34
+
35
+ // pkg/util.ts
36
+ function parseRecursive(obj) {
37
+ const parsed = Array.isArray(obj) ? obj.map((o) => {
38
+ try {
39
+ return parseRecursive(o);
40
+ } catch {
41
+ return o;
42
+ }
43
+ }) : JSON.parse(obj);
44
+ if (typeof parsed === "number" && parsed.toString() != obj) {
45
+ return obj;
46
+ }
47
+ return parsed;
48
+ }
49
+ function parseResponse(result) {
50
+ try {
51
+ return parseRecursive(result);
52
+ } catch {
53
+ return result;
54
+ }
55
+ }
56
+
57
+ // pkg/commands/command.ts
58
+ var defaultSerializer = (c) => {
59
+ switch (typeof c) {
60
+ case "string":
61
+ case "number":
62
+ case "boolean":
63
+ return c;
64
+ default:
65
+ return JSON.stringify(c);
66
+ }
67
+ };
68
+ var Command = class {
69
+ command;
70
+ serialize;
71
+ deserialize;
72
+ /**
73
+ * Create a new command instance.
74
+ *
75
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
76
+ */
77
+ constructor(command, opts) {
78
+ this.serialize = defaultSerializer;
79
+ this.deserialize = typeof opts?.automaticDeserialization === "undefined" || opts.automaticDeserialization ? opts?.deserialize ?? parseResponse : (x) => x;
80
+ this.command = command.map((c) => this.serialize(c));
81
+ }
82
+ /**
83
+ * Execute the command using a client.
84
+ */
85
+ async exec(client) {
86
+ const { result, error } = await client.request({
87
+ body: this.command
88
+ });
89
+ if (error) {
90
+ throw new UpstashError(error);
91
+ }
92
+ if (typeof result === "undefined") {
93
+ throw new Error("Request did not return a result");
94
+ }
95
+ return this.deserialize(result);
96
+ }
97
+ };
98
+
99
+ // pkg/commands/append.ts
100
+ var AppendCommand = class extends Command {
101
+ constructor(cmd, opts) {
102
+ super(["append", ...cmd], opts);
103
+ }
104
+ };
105
+
106
+ // pkg/commands/bitcount.ts
107
+ var BitCountCommand = class extends Command {
108
+ constructor([key, start, end], opts) {
109
+ const command = ["bitcount", key];
110
+ if (typeof start === "number") {
111
+ command.push(start);
112
+ }
113
+ if (typeof end === "number") {
114
+ command.push(end);
115
+ }
116
+ super(command, opts);
117
+ }
118
+ };
119
+
120
+ // pkg/commands/bitop.ts
121
+ var BitOpCommand = class extends Command {
122
+ constructor(cmd, opts) {
123
+ super(["bitop", ...cmd], opts);
124
+ }
125
+ };
126
+
127
+ // pkg/commands/bitpos.ts
128
+ var BitPosCommand = class extends Command {
129
+ constructor(cmd, opts) {
130
+ super(["bitpos", ...cmd], opts);
131
+ }
132
+ };
133
+
134
+ // pkg/commands/dbsize.ts
135
+ var DBSizeCommand = class extends Command {
136
+ constructor(opts) {
137
+ super(["dbsize"], opts);
138
+ }
139
+ };
140
+
141
+ // pkg/commands/decr.ts
142
+ var DecrCommand = class extends Command {
143
+ constructor(cmd, opts) {
144
+ super(["decr", ...cmd], opts);
145
+ }
146
+ };
147
+
148
+ // pkg/commands/decrby.ts
149
+ var DecrByCommand = class extends Command {
150
+ constructor(cmd, opts) {
151
+ super(["decrby", ...cmd], opts);
152
+ }
153
+ };
154
+
155
+ // pkg/commands/del.ts
156
+ var DelCommand = class extends Command {
157
+ constructor(cmd, opts) {
158
+ super(["del", ...cmd], opts);
159
+ }
160
+ };
161
+
162
+ // pkg/commands/echo.ts
163
+ var EchoCommand = class extends Command {
164
+ constructor(cmd, opts) {
165
+ super(["echo", ...cmd], opts);
166
+ }
167
+ };
168
+
169
+ // pkg/commands/eval.ts
170
+ var EvalCommand = class extends Command {
171
+ constructor([script, keys, args], opts) {
172
+ super(["eval", script, keys.length, ...keys, ...args ?? []], opts);
173
+ }
174
+ };
175
+
176
+ // pkg/commands/evalsha.ts
177
+ var EvalshaCommand = class extends Command {
178
+ constructor([sha, keys, args], opts) {
179
+ super(["evalsha", sha, keys.length, ...keys, ...args ?? []], opts);
180
+ }
181
+ };
182
+
183
+ // pkg/commands/exists.ts
184
+ var ExistsCommand = class extends Command {
185
+ constructor(cmd, opts) {
186
+ super(["exists", ...cmd], opts);
187
+ }
188
+ };
189
+
190
+ // pkg/commands/expire.ts
191
+ var ExpireCommand = class extends Command {
192
+ constructor(cmd, opts) {
193
+ super(["expire", ...cmd], opts);
194
+ }
195
+ };
196
+
197
+ // pkg/commands/expireat.ts
198
+ var ExpireAtCommand = class extends Command {
199
+ constructor(cmd, opts) {
200
+ super(["expireat", ...cmd], opts);
201
+ }
202
+ };
203
+
204
+ // pkg/commands/flushall.ts
205
+ var FlushAllCommand = class extends Command {
206
+ constructor(args, opts) {
207
+ const command = ["flushall"];
208
+ if (args && args.length > 0 && args[0].async) {
209
+ command.push("async");
210
+ }
211
+ super(command, opts);
212
+ }
213
+ };
214
+
215
+ // pkg/commands/flushdb.ts
216
+ var FlushDBCommand = class extends Command {
217
+ constructor([opts], cmdOpts) {
218
+ const command = ["flushdb"];
219
+ if (opts?.async) {
220
+ command.push("async");
221
+ }
222
+ super(command, cmdOpts);
223
+ }
224
+ };
225
+
226
+ // pkg/commands/geo_add.ts
227
+ var GeoAddCommand = class extends Command {
228
+ constructor([key, arg1, ...arg2], opts) {
229
+ const command = ["geoadd", key];
230
+ if ("nx" in arg1 && arg1.nx) {
231
+ command.push("nx");
232
+ } else if ("xx" in arg1 && arg1.xx) {
233
+ command.push("xx");
234
+ }
235
+ if ("ch" in arg1 && arg1.ch) {
236
+ command.push("ch");
237
+ }
238
+ if ("latitude" in arg1 && arg1.latitude) {
239
+ command.push(arg1.longitude, arg1.latitude, arg1.member);
240
+ }
241
+ command.push(
242
+ ...arg2.flatMap(({ latitude, longitude, member }) => [
243
+ longitude,
244
+ latitude,
245
+ member
246
+ ])
247
+ );
248
+ super(command, opts);
249
+ }
250
+ };
251
+
252
+ // pkg/commands/get.ts
253
+ var GetCommand = class extends Command {
254
+ constructor(cmd, opts) {
255
+ super(["get", ...cmd], opts);
256
+ }
257
+ };
258
+
259
+ // pkg/commands/getbit.ts
260
+ var GetBitCommand = class extends Command {
261
+ constructor(cmd, opts) {
262
+ super(["getbit", ...cmd], opts);
263
+ }
264
+ };
265
+
266
+ // pkg/commands/getdel.ts
267
+ var GetDelCommand = class extends Command {
268
+ constructor(cmd, opts) {
269
+ super(["getdel", ...cmd], opts);
270
+ }
271
+ };
272
+
273
+ // pkg/commands/getrange.ts
274
+ var GetRangeCommand = class extends Command {
275
+ constructor(cmd, opts) {
276
+ super(["getrange", ...cmd], opts);
277
+ }
278
+ };
279
+
280
+ // pkg/commands/getset.ts
281
+ var GetSetCommand = class extends Command {
282
+ constructor(cmd, opts) {
283
+ super(["getset", ...cmd], opts);
284
+ }
285
+ };
286
+
287
+ // pkg/commands/hdel.ts
288
+ var HDelCommand = class extends Command {
289
+ constructor(cmd, opts) {
290
+ super(["hdel", ...cmd], opts);
291
+ }
292
+ };
293
+
294
+ // pkg/commands/hexists.ts
295
+ var HExistsCommand = class extends Command {
296
+ constructor(cmd, opts) {
297
+ super(["hexists", ...cmd], opts);
298
+ }
299
+ };
300
+
301
+ // pkg/commands/hget.ts
302
+ var HGetCommand = class extends Command {
303
+ constructor(cmd, opts) {
304
+ super(["hget", ...cmd], opts);
305
+ }
306
+ };
307
+
308
+ // pkg/commands/hgetall.ts
309
+ function deserialize(result) {
310
+ if (result.length === 0) {
311
+ return null;
312
+ }
313
+ const obj = {};
314
+ while (result.length >= 2) {
315
+ const key = result.shift();
316
+ const value = result.shift();
317
+ try {
318
+ const valueIsNumberAndNotSafeInteger = !isNaN(Number(value)) && !Number.isSafeInteger(value);
319
+ if (valueIsNumberAndNotSafeInteger) {
320
+ obj[key] = value;
321
+ } else {
322
+ obj[key] = JSON.parse(value);
323
+ }
324
+ } catch {
325
+ obj[key] = value;
326
+ }
327
+ }
328
+ return obj;
329
+ }
330
+ var HGetAllCommand = class extends Command {
331
+ constructor(cmd, opts) {
332
+ super(["hgetall", ...cmd], {
333
+ deserialize: (result) => deserialize(result),
334
+ ...opts
335
+ });
336
+ }
337
+ };
338
+
339
+ // pkg/commands/hincrby.ts
340
+ var HIncrByCommand = class extends Command {
341
+ constructor(cmd, opts) {
342
+ super(["hincrby", ...cmd], opts);
343
+ }
344
+ };
345
+
346
+ // pkg/commands/hincrbyfloat.ts
347
+ var HIncrByFloatCommand = class extends Command {
348
+ constructor(cmd, opts) {
349
+ super(["hincrbyfloat", ...cmd], opts);
350
+ }
351
+ };
352
+
353
+ // pkg/commands/hkeys.ts
354
+ var HKeysCommand = class extends Command {
355
+ constructor([key], opts) {
356
+ super(["hkeys", key], opts);
357
+ }
358
+ };
359
+
360
+ // pkg/commands/hlen.ts
361
+ var HLenCommand = class extends Command {
362
+ constructor(cmd, opts) {
363
+ super(["hlen", ...cmd], opts);
364
+ }
365
+ };
366
+
367
+ // pkg/commands/hmget.ts
368
+ function deserialize2(fields, result) {
369
+ if (result.length === 0 || result.every((field) => field === null)) {
370
+ return null;
371
+ }
372
+ const obj = {};
373
+ for (let i = 0; i < fields.length; i++) {
374
+ try {
375
+ obj[fields[i]] = JSON.parse(result[i]);
376
+ } catch {
377
+ obj[fields[i]] = result[i];
378
+ }
379
+ }
380
+ return obj;
381
+ }
382
+ var HMGetCommand = class extends Command {
383
+ constructor([key, ...fields], opts) {
384
+ super(["hmget", key, ...fields], {
385
+ deserialize: (result) => deserialize2(fields, result),
386
+ ...opts
387
+ });
388
+ }
389
+ };
390
+
391
+ // pkg/commands/hmset.ts
392
+ var HMSetCommand = class extends Command {
393
+ constructor([key, kv], opts) {
394
+ super(
395
+ [
396
+ "hmset",
397
+ key,
398
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
399
+ ],
400
+ opts
401
+ );
402
+ }
403
+ };
404
+
405
+ // pkg/commands/hrandfield.ts
406
+ function deserialize3(result) {
407
+ if (result.length === 0) {
408
+ return null;
409
+ }
410
+ const obj = {};
411
+ while (result.length >= 2) {
412
+ const key = result.shift();
413
+ const value = result.shift();
414
+ try {
415
+ obj[key] = JSON.parse(value);
416
+ } catch {
417
+ obj[key] = value;
418
+ }
419
+ }
420
+ return obj;
421
+ }
422
+ var HRandFieldCommand = class extends Command {
423
+ constructor(cmd, opts) {
424
+ const command = ["hrandfield", cmd[0]];
425
+ if (typeof cmd[1] === "number") {
426
+ command.push(cmd[1]);
427
+ }
428
+ if (cmd[2]) {
429
+ command.push("WITHVALUES");
430
+ }
431
+ super(command, {
432
+ // @ts-ignore TODO:
433
+ deserialize: cmd[2] ? (result) => deserialize3(result) : opts?.deserialize,
434
+ ...opts
435
+ });
436
+ }
437
+ };
438
+
439
+ // pkg/commands/hscan.ts
440
+ var HScanCommand = class extends Command {
441
+ constructor([key, cursor, cmdOpts], opts) {
442
+ const command = ["hscan", key, cursor];
443
+ if (cmdOpts?.match) {
444
+ command.push("match", cmdOpts.match);
445
+ }
446
+ if (typeof cmdOpts?.count === "number") {
447
+ command.push("count", cmdOpts.count);
448
+ }
449
+ super(command, opts);
450
+ }
451
+ };
452
+
453
+ // pkg/commands/hset.ts
454
+ var HSetCommand = class extends Command {
455
+ constructor([key, kv], opts) {
456
+ super([
457
+ "hset",
458
+ key,
459
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
460
+ ], opts);
461
+ }
462
+ };
463
+
464
+ // pkg/commands/hsetnx.ts
465
+ var HSetNXCommand = class extends Command {
466
+ constructor(cmd, opts) {
467
+ super(["hsetnx", ...cmd], opts);
468
+ }
469
+ };
470
+
471
+ // pkg/commands/hstrlen.ts
472
+ var HStrLenCommand = class extends Command {
473
+ constructor(cmd, opts) {
474
+ super(["hstrlen", ...cmd], opts);
475
+ }
476
+ };
477
+
478
+ // pkg/commands/hvals.ts
479
+ var HValsCommand = class extends Command {
480
+ constructor(cmd, opts) {
481
+ super(["hvals", ...cmd], opts);
482
+ }
483
+ };
484
+
485
+ // pkg/commands/incr.ts
486
+ var IncrCommand = class extends Command {
487
+ constructor(cmd, opts) {
488
+ super(["incr", ...cmd], opts);
489
+ }
490
+ };
491
+
492
+ // pkg/commands/incrby.ts
493
+ var IncrByCommand = class extends Command {
494
+ constructor(cmd, opts) {
495
+ super(["incrby", ...cmd], opts);
496
+ }
497
+ };
498
+
499
+ // pkg/commands/incrbyfloat.ts
500
+ var IncrByFloatCommand = class extends Command {
501
+ constructor(cmd, opts) {
502
+ super(["incrbyfloat", ...cmd], opts);
503
+ }
504
+ };
505
+
506
+ // pkg/commands/json_arrappend.ts
507
+ var JsonArrAppendCommand = class extends Command {
508
+ constructor(cmd, opts) {
509
+ super(["JSON.ARRAPPEND", ...cmd], opts);
510
+ }
511
+ };
512
+
513
+ // pkg/commands/json_arrindex.ts
514
+ var JsonArrIndexCommand = class extends Command {
515
+ constructor(cmd, opts) {
516
+ super(["JSON.ARRINDEX", ...cmd], opts);
517
+ }
518
+ };
519
+
520
+ // pkg/commands/json_arrinsert.ts
521
+ var JsonArrInsertCommand = class extends Command {
522
+ constructor(cmd, opts) {
523
+ super(["JSON.ARRINSERT", ...cmd], opts);
524
+ }
525
+ };
526
+
527
+ // pkg/commands/json_arrlen.ts
528
+ var JsonArrLenCommand = class extends Command {
529
+ constructor(cmd, opts) {
530
+ super(["JSON.ARRLEN", cmd[0], cmd[1] ?? "$"], opts);
531
+ }
532
+ };
533
+
534
+ // pkg/commands/json_arrpop.ts
535
+ var JsonArrPopCommand = class extends Command {
536
+ constructor(cmd, opts) {
537
+ super(["JSON.ARRPOP", ...cmd], opts);
538
+ }
539
+ };
540
+
541
+ // pkg/commands/json_arrtrim.ts
542
+ var JsonArrTrimCommand = class extends Command {
543
+ constructor(cmd, opts) {
544
+ const path = cmd[1] ?? "$";
545
+ const start = cmd[2] ?? 0;
546
+ const stop = cmd[3] ?? 0;
547
+ super(["JSON.ARRTRIM", cmd[0], path, start, stop], opts);
548
+ }
549
+ };
550
+
551
+ // pkg/commands/json_clear.ts
552
+ var JsonClearCommand = class extends Command {
553
+ constructor(cmd, opts) {
554
+ super(["JSON.CLEAR", ...cmd], opts);
555
+ }
556
+ };
557
+
558
+ // pkg/commands/json_del.ts
559
+ var JsonDelCommand = class extends Command {
560
+ constructor(cmd, opts) {
561
+ super(["JSON.DEL", ...cmd], opts);
562
+ }
563
+ };
564
+
565
+ // pkg/commands/json_forget.ts
566
+ var JsonForgetCommand = class extends Command {
567
+ constructor(cmd, opts) {
568
+ super(["JSON.FORGET", ...cmd], opts);
569
+ }
570
+ };
571
+
572
+ // pkg/commands/json_get.ts
573
+ var JsonGetCommand = class extends Command {
574
+ constructor(cmd, opts) {
575
+ const command = ["JSON.GET"];
576
+ if (typeof cmd[1] === "string") {
577
+ command.push(...cmd);
578
+ } else {
579
+ command.push(cmd[0]);
580
+ if (cmd[1]) {
581
+ if (cmd[1].indent) {
582
+ command.push("INDENT", cmd[1].indent);
583
+ }
584
+ if (cmd[1].newline) {
585
+ command.push("NEWLINE", cmd[1].newline);
586
+ }
587
+ if (cmd[1].space) {
588
+ command.push("SPACE", cmd[1].space);
589
+ }
590
+ }
591
+ command.push(...cmd.slice(2));
592
+ }
593
+ super(command, opts);
594
+ }
595
+ };
596
+
597
+ // pkg/commands/json_mget.ts
598
+ var JsonMGetCommand = class extends Command {
599
+ constructor(cmd, opts) {
600
+ super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
601
+ }
602
+ };
603
+
604
+ // pkg/commands/json_numincrby.ts
605
+ var JsonNumIncrByCommand = class extends Command {
606
+ constructor(cmd, opts) {
607
+ super(["JSON.NUMINCRBY", ...cmd], opts);
608
+ }
609
+ };
610
+
611
+ // pkg/commands/json_nummultby.ts
612
+ var JsonNumMultByCommand = class extends Command {
613
+ constructor(cmd, opts) {
614
+ super(["JSON.NUMMULTBY", ...cmd], opts);
615
+ }
616
+ };
617
+
618
+ // pkg/commands/json_objkeys.ts
619
+ var JsonObjKeysCommand = class extends Command {
620
+ constructor(cmd, opts) {
621
+ super(["JSON.OBJKEYS", ...cmd], opts);
622
+ }
623
+ };
624
+
625
+ // pkg/commands/json_objlen.ts
626
+ var JsonObjLenCommand = class extends Command {
627
+ constructor(cmd, opts) {
628
+ super(["JSON.OBJLEN", ...cmd], opts);
629
+ }
630
+ };
631
+
632
+ // pkg/commands/json_resp.ts
633
+ var JsonRespCommand = class extends Command {
634
+ constructor(cmd, opts) {
635
+ super(["JSON.RESP", ...cmd], opts);
636
+ }
637
+ };
638
+
639
+ // pkg/commands/json_set.ts
640
+ var JsonSetCommand = class extends Command {
641
+ constructor(cmd, opts) {
642
+ const command = ["JSON.SET", cmd[0], cmd[1], cmd[2]];
643
+ if (cmd[3]) {
644
+ if (cmd[3].nx) {
645
+ command.push("NX");
646
+ } else if (cmd[3].xx) {
647
+ command.push("XX");
648
+ }
649
+ }
650
+ super(command, opts);
651
+ }
652
+ };
653
+
654
+ // pkg/commands/json_strappend.ts
655
+ var JsonStrAppendCommand = class extends Command {
656
+ constructor(cmd, opts) {
657
+ super(["JSON.STRAPPEND", ...cmd], opts);
658
+ }
659
+ };
660
+
661
+ // pkg/commands/json_strlen.ts
662
+ var JsonStrLenCommand = class extends Command {
663
+ constructor(cmd, opts) {
664
+ super(["JSON.STRLEN", ...cmd], opts);
665
+ }
666
+ };
667
+
668
+ // pkg/commands/json_toggle.ts
669
+ var JsonToggleCommand = class extends Command {
670
+ constructor(cmd, opts) {
671
+ super(["JSON.TOGGLE", ...cmd], opts);
672
+ }
673
+ };
674
+
675
+ // pkg/commands/json_type.ts
676
+ var JsonTypeCommand = class extends Command {
677
+ constructor(cmd, opts) {
678
+ super(["JSON.TYPE", ...cmd], opts);
679
+ }
680
+ };
681
+
682
+ // pkg/commands/keys.ts
683
+ var KeysCommand = class extends Command {
684
+ constructor(cmd, opts) {
685
+ super(["keys", ...cmd], opts);
686
+ }
687
+ };
688
+
689
+ // pkg/commands/lindex.ts
690
+ var LIndexCommand = class extends Command {
691
+ constructor(cmd, opts) {
692
+ super(["lindex", ...cmd], opts);
693
+ }
694
+ };
695
+
696
+ // pkg/commands/linsert.ts
697
+ var LInsertCommand = class extends Command {
698
+ constructor(cmd, opts) {
699
+ super(["linsert", ...cmd], opts);
700
+ }
701
+ };
702
+
703
+ // pkg/commands/llen.ts
704
+ var LLenCommand = class extends Command {
705
+ constructor(cmd, opts) {
706
+ super(["llen", ...cmd], opts);
707
+ }
708
+ };
709
+
710
+ // pkg/commands/lmove.ts
711
+ var LMoveCommand = class extends Command {
712
+ constructor(cmd, opts) {
713
+ super(["lmove", ...cmd], opts);
714
+ }
715
+ };
716
+
717
+ // pkg/commands/lpop.ts
718
+ var LPopCommand = class extends Command {
719
+ constructor(cmd, opts) {
720
+ super(["lpop", ...cmd], opts);
721
+ }
722
+ };
723
+
724
+ // pkg/commands/lpos.ts
725
+ var LPosCommand = class extends Command {
726
+ constructor(cmd, opts) {
727
+ const args = ["lpos", cmd[0], cmd[1]];
728
+ if (typeof cmd[2]?.rank === "number") {
729
+ args.push("rank", cmd[2].rank);
730
+ }
731
+ if (typeof cmd[2]?.count === "number") {
732
+ args.push("count", cmd[2].count);
733
+ }
734
+ if (typeof cmd[2]?.maxLen === "number") {
735
+ args.push("maxLen", cmd[2].maxLen);
736
+ }
737
+ super(args, opts);
738
+ }
739
+ };
740
+
741
+ // pkg/commands/lpush.ts
742
+ var LPushCommand = class extends Command {
743
+ constructor(cmd, opts) {
744
+ super(["lpush", ...cmd], opts);
745
+ }
746
+ };
747
+
748
+ // pkg/commands/lpushx.ts
749
+ var LPushXCommand = class extends Command {
750
+ constructor(cmd, opts) {
751
+ super(["lpushx", ...cmd], opts);
752
+ }
753
+ };
754
+
755
+ // pkg/commands/lrange.ts
756
+ var LRangeCommand = class extends Command {
757
+ constructor(cmd, opts) {
758
+ super(["lrange", ...cmd], opts);
759
+ }
760
+ };
761
+
762
+ // pkg/commands/lrem.ts
763
+ var LRemCommand = class extends Command {
764
+ constructor(cmd, opts) {
765
+ super(["lrem", ...cmd], opts);
766
+ }
767
+ };
768
+
769
+ // pkg/commands/lset.ts
770
+ var LSetCommand = class extends Command {
771
+ constructor(cmd, opts) {
772
+ super(["lset", ...cmd], opts);
773
+ }
774
+ };
775
+
776
+ // pkg/commands/ltrim.ts
777
+ var LTrimCommand = class extends Command {
778
+ constructor(cmd, opts) {
779
+ super(["ltrim", ...cmd], opts);
780
+ }
781
+ };
782
+
783
+ // pkg/commands/mget.ts
784
+ var MGetCommand = class extends Command {
785
+ constructor(cmd, opts) {
786
+ super(["mget", ...cmd], opts);
787
+ }
788
+ };
789
+
790
+ // pkg/commands/mset.ts
791
+ var MSetCommand = class extends Command {
792
+ constructor([kv], opts) {
793
+ super([
794
+ "mset",
795
+ ...Object.entries(kv).flatMap(([key, value]) => [key, value])
796
+ ], opts);
797
+ }
798
+ };
799
+
800
+ // pkg/commands/msetnx.ts
801
+ var MSetNXCommand = class extends Command {
802
+ constructor([kv], opts) {
803
+ super(["msetnx", ...Object.entries(kv).flatMap((_) => _)], opts);
804
+ }
805
+ };
806
+
807
+ // pkg/commands/persist.ts
808
+ var PersistCommand = class extends Command {
809
+ constructor(cmd, opts) {
810
+ super(["persist", ...cmd], opts);
811
+ }
812
+ };
813
+
814
+ // pkg/commands/pexpire.ts
815
+ var PExpireCommand = class extends Command {
816
+ constructor(cmd, opts) {
817
+ super(["pexpire", ...cmd], opts);
818
+ }
819
+ };
820
+
821
+ // pkg/commands/pexpireat.ts
822
+ var PExpireAtCommand = class extends Command {
823
+ constructor(cmd, opts) {
824
+ super(["pexpireat", ...cmd], opts);
825
+ }
826
+ };
827
+
828
+ // pkg/commands/ping.ts
829
+ var PingCommand = class extends Command {
830
+ constructor(cmd, opts) {
831
+ const command = ["ping"];
832
+ if (typeof cmd !== "undefined" && typeof cmd[0] !== "undefined") {
833
+ command.push(cmd[0]);
834
+ }
835
+ super(command, opts);
836
+ }
837
+ };
838
+
839
+ // pkg/commands/psetex.ts
840
+ var PSetEXCommand = class extends Command {
841
+ constructor(cmd, opts) {
842
+ super(["psetex", ...cmd], opts);
843
+ }
844
+ };
845
+
846
+ // pkg/commands/pttl.ts
847
+ var PTtlCommand = class extends Command {
848
+ constructor(cmd, opts) {
849
+ super(["pttl", ...cmd], opts);
850
+ }
851
+ };
852
+
853
+ // pkg/commands/publish.ts
854
+ var PublishCommand = class extends Command {
855
+ constructor(cmd, opts) {
856
+ super(["publish", ...cmd], opts);
857
+ }
858
+ };
859
+
860
+ // pkg/commands/randomkey.ts
861
+ var RandomKeyCommand = class extends Command {
862
+ constructor(opts) {
863
+ super(["randomkey"], opts);
864
+ }
865
+ };
866
+
867
+ // pkg/commands/rename.ts
868
+ var RenameCommand = class extends Command {
869
+ constructor(cmd, opts) {
870
+ super(["rename", ...cmd], opts);
871
+ }
872
+ };
873
+
874
+ // pkg/commands/renamenx.ts
875
+ var RenameNXCommand = class extends Command {
876
+ constructor(cmd, opts) {
877
+ super(["renamenx", ...cmd], opts);
878
+ }
879
+ };
880
+
881
+ // pkg/commands/rpop.ts
882
+ var RPopCommand = class extends Command {
883
+ constructor(cmd, opts) {
884
+ super(["rpop", ...cmd], opts);
885
+ }
886
+ };
887
+
888
+ // pkg/commands/rpush.ts
889
+ var RPushCommand = class extends Command {
890
+ constructor(cmd, opts) {
891
+ super(["rpush", ...cmd], opts);
892
+ }
893
+ };
894
+
895
+ // pkg/commands/rpushx.ts
896
+ var RPushXCommand = class extends Command {
897
+ constructor(cmd, opts) {
898
+ super(["rpushx", ...cmd], opts);
899
+ }
900
+ };
901
+
902
+ // pkg/commands/sadd.ts
903
+ var SAddCommand = class extends Command {
904
+ constructor(cmd, opts) {
905
+ super(["sadd", ...cmd], opts);
906
+ }
907
+ };
908
+
909
+ // pkg/commands/scan.ts
910
+ var ScanCommand = class extends Command {
911
+ constructor([cursor, opts], cmdOpts) {
912
+ const command = ["scan", cursor];
913
+ if (opts?.match) {
914
+ command.push("match", opts.match);
915
+ }
916
+ if (typeof opts?.count === "number") {
917
+ command.push("count", opts.count);
918
+ }
919
+ if (opts?.type && opts.type.length > 0) {
920
+ command.push("type", opts.type);
921
+ }
922
+ super(command, cmdOpts);
923
+ }
924
+ };
925
+
926
+ // pkg/commands/scard.ts
927
+ var SCardCommand = class extends Command {
928
+ constructor(cmd, opts) {
929
+ super(["scard", ...cmd], opts);
930
+ }
931
+ };
932
+
933
+ // pkg/commands/script_exists.ts
934
+ var ScriptExistsCommand = class extends Command {
935
+ constructor(hashes, opts) {
936
+ super(["script", "exists", ...hashes], {
937
+ deserialize: (result) => result,
938
+ ...opts
939
+ });
940
+ }
941
+ };
942
+
943
+ // pkg/commands/script_flush.ts
944
+ var ScriptFlushCommand = class extends Command {
945
+ constructor([opts], cmdOpts) {
946
+ const cmd = ["script", "flush"];
947
+ if (opts?.sync) {
948
+ cmd.push("sync");
949
+ } else if (opts?.async) {
950
+ cmd.push("async");
951
+ }
952
+ super(cmd, cmdOpts);
953
+ }
954
+ };
955
+
956
+ // pkg/commands/script_load.ts
957
+ var ScriptLoadCommand = class extends Command {
958
+ constructor(args, opts) {
959
+ super(["script", "load", ...args], opts);
960
+ }
961
+ };
962
+
963
+ // pkg/commands/sdiff.ts
964
+ var SDiffCommand = class extends Command {
965
+ constructor(cmd, opts) {
966
+ super(["sdiff", ...cmd], opts);
967
+ }
968
+ };
969
+
970
+ // pkg/commands/sdiffstore.ts
971
+ var SDiffStoreCommand = class extends Command {
972
+ constructor(cmd, opts) {
973
+ super(["sdiffstore", ...cmd], opts);
974
+ }
975
+ };
976
+
977
+ // pkg/commands/set.ts
978
+ var SetCommand = class extends Command {
979
+ constructor([key, value, opts], cmdOpts) {
980
+ const command = ["set", key, value];
981
+ if (opts) {
982
+ if ("nx" in opts && opts.nx) {
983
+ command.push("nx");
984
+ } else if ("xx" in opts && opts.xx) {
985
+ command.push("xx");
986
+ }
987
+ if ("get" in opts && opts.get) {
988
+ command.push("get");
989
+ }
990
+ if ("ex" in opts && typeof opts.ex === "number") {
991
+ command.push("ex", opts.ex);
992
+ } else if ("px" in opts && typeof opts.px === "number") {
993
+ command.push("px", opts.px);
994
+ } else if ("exat" in opts && typeof opts.exat === "number") {
995
+ command.push("exat", opts.exat);
996
+ } else if ("pxat" in opts && typeof opts.pxat === "number") {
997
+ command.push("pxat", opts.pxat);
998
+ } else if ("keepTtl" in opts && opts.keepTtl) {
999
+ command.push("keepTtl");
1000
+ }
1001
+ }
1002
+ super(command, cmdOpts);
1003
+ }
1004
+ };
1005
+
1006
+ // pkg/commands/setbit.ts
1007
+ var SetBitCommand = class extends Command {
1008
+ constructor(cmd, opts) {
1009
+ super(["setbit", ...cmd], opts);
1010
+ }
1011
+ };
1012
+
1013
+ // pkg/commands/setex.ts
1014
+ var SetExCommand = class extends Command {
1015
+ constructor(cmd, opts) {
1016
+ super(["setex", ...cmd], opts);
1017
+ }
1018
+ };
1019
+
1020
+ // pkg/commands/setnx.ts
1021
+ var SetNxCommand = class extends Command {
1022
+ constructor(cmd, opts) {
1023
+ super(["setnx", ...cmd], opts);
1024
+ }
1025
+ };
1026
+
1027
+ // pkg/commands/setrange.ts
1028
+ var SetRangeCommand = class extends Command {
1029
+ constructor(cmd, opts) {
1030
+ super(["setrange", ...cmd], opts);
1031
+ }
1032
+ };
1033
+
1034
+ // pkg/commands/sinter.ts
1035
+ var SInterCommand = class extends Command {
1036
+ constructor(cmd, opts) {
1037
+ super(["sinter", ...cmd], opts);
1038
+ }
1039
+ };
1040
+
1041
+ // pkg/commands/sinterstore.ts
1042
+ var SInterStoreCommand = class extends Command {
1043
+ constructor(cmd, opts) {
1044
+ super(["sinterstore", ...cmd], opts);
1045
+ }
1046
+ };
1047
+
1048
+ // pkg/commands/sismember.ts
1049
+ var SIsMemberCommand = class extends Command {
1050
+ constructor(cmd, opts) {
1051
+ super(["sismember", ...cmd], opts);
1052
+ }
1053
+ };
1054
+
1055
+ // pkg/commands/smembers.ts
1056
+ var SMembersCommand = class extends Command {
1057
+ constructor(cmd, opts) {
1058
+ super(["smembers", ...cmd], opts);
1059
+ }
1060
+ };
1061
+
1062
+ // pkg/commands/smismember.ts
1063
+ var SMIsMemberCommand = class extends Command {
1064
+ constructor(cmd, opts) {
1065
+ super(["smismember", cmd[0], ...cmd[1]], opts);
1066
+ }
1067
+ };
1068
+
1069
+ // pkg/commands/smove.ts
1070
+ var SMoveCommand = class extends Command {
1071
+ constructor(cmd, opts) {
1072
+ super(["smove", ...cmd], opts);
1073
+ }
1074
+ };
1075
+
1076
+ // pkg/commands/spop.ts
1077
+ var SPopCommand = class extends Command {
1078
+ constructor([key, count], opts) {
1079
+ const command = ["spop", key];
1080
+ if (typeof count === "number") {
1081
+ command.push(count);
1082
+ }
1083
+ super(command, opts);
1084
+ }
1085
+ };
1086
+
1087
+ // pkg/commands/srandmember.ts
1088
+ var SRandMemberCommand = class extends Command {
1089
+ constructor([key, count], opts) {
1090
+ const command = ["srandmember", key];
1091
+ if (typeof count === "number") {
1092
+ command.push(count);
1093
+ }
1094
+ super(command, opts);
1095
+ }
1096
+ };
1097
+
1098
+ // pkg/commands/srem.ts
1099
+ var SRemCommand = class extends Command {
1100
+ constructor(cmd, opts) {
1101
+ super(["srem", ...cmd], opts);
1102
+ }
1103
+ };
1104
+
1105
+ // pkg/commands/sscan.ts
1106
+ var SScanCommand = class extends Command {
1107
+ constructor([key, cursor, opts], cmdOpts) {
1108
+ const command = ["sscan", key, cursor];
1109
+ if (opts?.match) {
1110
+ command.push("match", opts.match);
1111
+ }
1112
+ if (typeof opts?.count === "number") {
1113
+ command.push("count", opts.count);
1114
+ }
1115
+ super(command, cmdOpts);
1116
+ }
1117
+ };
1118
+
1119
+ // pkg/commands/strlen.ts
1120
+ var StrLenCommand = class extends Command {
1121
+ constructor(cmd, opts) {
1122
+ super(["strlen", ...cmd], opts);
1123
+ }
1124
+ };
1125
+
1126
+ // pkg/commands/sunion.ts
1127
+ var SUnionCommand = class extends Command {
1128
+ constructor(cmd, opts) {
1129
+ super(["sunion", ...cmd], opts);
1130
+ }
1131
+ };
1132
+
1133
+ // pkg/commands/sunionstore.ts
1134
+ var SUnionStoreCommand = class extends Command {
1135
+ constructor(cmd, opts) {
1136
+ super(["sunionstore", ...cmd], opts);
1137
+ }
1138
+ };
1139
+
1140
+ // pkg/commands/time.ts
1141
+ var TimeCommand = class extends Command {
1142
+ constructor(opts) {
1143
+ super(["time"], opts);
1144
+ }
1145
+ };
1146
+
1147
+ // pkg/commands/touch.ts
1148
+ var TouchCommand = class extends Command {
1149
+ constructor(cmd, opts) {
1150
+ super(["touch", ...cmd], opts);
1151
+ }
1152
+ };
1153
+
1154
+ // pkg/commands/ttl.ts
1155
+ var TtlCommand = class extends Command {
1156
+ constructor(cmd, opts) {
1157
+ super(["ttl", ...cmd], opts);
1158
+ }
1159
+ };
1160
+
1161
+ // pkg/commands/type.ts
1162
+ var TypeCommand = class extends Command {
1163
+ constructor(cmd, opts) {
1164
+ super(["type", ...cmd], opts);
1165
+ }
1166
+ };
1167
+
1168
+ // pkg/commands/unlink.ts
1169
+ var UnlinkCommand = class extends Command {
1170
+ constructor(cmd, opts) {
1171
+ super(["unlink", ...cmd], opts);
1172
+ }
1173
+ };
1174
+
1175
+ // pkg/commands/zadd.ts
1176
+ var ZAddCommand = class extends Command {
1177
+ constructor([key, arg1, ...arg2], opts) {
1178
+ const command = ["zadd", key];
1179
+ if ("nx" in arg1 && arg1.nx) {
1180
+ command.push("nx");
1181
+ } else if ("xx" in arg1 && arg1.xx) {
1182
+ command.push("xx");
1183
+ }
1184
+ if ("ch" in arg1 && arg1.ch) {
1185
+ command.push("ch");
1186
+ }
1187
+ if ("incr" in arg1 && arg1.incr) {
1188
+ command.push("incr");
1189
+ }
1190
+ if ("score" in arg1 && "member" in arg1) {
1191
+ command.push(arg1.score, arg1.member);
1192
+ }
1193
+ command.push(...arg2.flatMap(({ score, member }) => [score, member]));
1194
+ super(command, opts);
1195
+ }
1196
+ };
1197
+
1198
+ // pkg/commands/zcard.ts
1199
+ var ZCardCommand = class extends Command {
1200
+ constructor(cmd, opts) {
1201
+ super(["zcard", ...cmd], opts);
1202
+ }
1203
+ };
1204
+
1205
+ // pkg/commands/zcount.ts
1206
+ var ZCountCommand = class extends Command {
1207
+ constructor(cmd, opts) {
1208
+ super(["zcount", ...cmd], opts);
1209
+ }
1210
+ };
1211
+
1212
+ // pkg/commands/zincrby.ts
1213
+ var ZIncrByCommand = class extends Command {
1214
+ constructor(cmd, opts) {
1215
+ super(["zincrby", ...cmd], opts);
1216
+ }
1217
+ };
1218
+
1219
+ // pkg/commands/zinterstore.ts
1220
+ var ZInterStoreCommand = class extends Command {
1221
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
1222
+ const command = ["zinterstore", destination, numKeys];
1223
+ if (Array.isArray(keyOrKeys)) {
1224
+ command.push(...keyOrKeys);
1225
+ } else {
1226
+ command.push(keyOrKeys);
1227
+ }
1228
+ if (opts) {
1229
+ if ("weights" in opts && opts.weights) {
1230
+ command.push("weights", ...opts.weights);
1231
+ } else if ("weight" in opts && typeof opts.weight === "number") {
1232
+ command.push("weights", opts.weight);
1233
+ }
1234
+ if ("aggregate" in opts) {
1235
+ command.push("aggregate", opts.aggregate);
1236
+ }
1237
+ }
1238
+ super(command, cmdOpts);
1239
+ }
1240
+ };
1241
+
1242
+ // pkg/commands/zlexcount.ts
1243
+ var ZLexCountCommand = class extends Command {
1244
+ constructor(cmd, opts) {
1245
+ super(["zlexcount", ...cmd], opts);
1246
+ }
1247
+ };
1248
+
1249
+ // pkg/commands/zpopmax.ts
1250
+ var ZPopMaxCommand = class extends Command {
1251
+ constructor([key, count], opts) {
1252
+ const command = ["zpopmax", key];
1253
+ if (typeof count === "number") {
1254
+ command.push(count);
1255
+ }
1256
+ super(command, opts);
1257
+ }
1258
+ };
1259
+
1260
+ // pkg/commands/zpopmin.ts
1261
+ var ZPopMinCommand = class extends Command {
1262
+ constructor([key, count], opts) {
1263
+ const command = ["zpopmin", key];
1264
+ if (typeof count === "number") {
1265
+ command.push(count);
1266
+ }
1267
+ super(command, opts);
1268
+ }
1269
+ };
1270
+
1271
+ // pkg/commands/zrange.ts
1272
+ var ZRangeCommand = class extends Command {
1273
+ constructor([key, min, max, opts], cmdOpts) {
1274
+ const command = ["zrange", key, min, max];
1275
+ if (opts?.byScore) {
1276
+ command.push("byscore");
1277
+ }
1278
+ if (opts?.byLex) {
1279
+ command.push("bylex");
1280
+ }
1281
+ if (opts?.rev) {
1282
+ command.push("rev");
1283
+ }
1284
+ if (typeof opts?.count !== "undefined" && typeof opts?.offset !== "undefined") {
1285
+ command.push("limit", opts.offset, opts.count);
1286
+ }
1287
+ if (opts?.withScores) {
1288
+ command.push("withscores");
1289
+ }
1290
+ super(command, cmdOpts);
1291
+ }
1292
+ };
1293
+
1294
+ // pkg/commands/zrank.ts
1295
+ var ZRankCommand = class extends Command {
1296
+ constructor(cmd, opts) {
1297
+ super(["zrank", ...cmd], opts);
1298
+ }
1299
+ };
1300
+
1301
+ // pkg/commands/zrem.ts
1302
+ var ZRemCommand = class extends Command {
1303
+ constructor(cmd, opts) {
1304
+ super(["zrem", ...cmd], opts);
1305
+ }
1306
+ };
1307
+
1308
+ // pkg/commands/zremrangebylex.ts
1309
+ var ZRemRangeByLexCommand = class extends Command {
1310
+ constructor(cmd, opts) {
1311
+ super(["zremrangebylex", ...cmd], opts);
1312
+ }
1313
+ };
1314
+
1315
+ // pkg/commands/zremrangebyrank.ts
1316
+ var ZRemRangeByRankCommand = class extends Command {
1317
+ constructor(cmd, opts) {
1318
+ super(["zremrangebyrank", ...cmd], opts);
1319
+ }
1320
+ };
1321
+
1322
+ // pkg/commands/zremrangebyscore.ts
1323
+ var ZRemRangeByScoreCommand = class extends Command {
1324
+ constructor(cmd, opts) {
1325
+ super(["zremrangebyscore", ...cmd], opts);
1326
+ }
1327
+ };
1328
+
1329
+ // pkg/commands/zrevrank.ts
1330
+ var ZRevRankCommand = class extends Command {
1331
+ constructor(cmd, opts) {
1332
+ super(["zrevrank", ...cmd], opts);
1333
+ }
1334
+ };
1335
+
1336
+ // pkg/commands/zscan.ts
1337
+ var ZScanCommand = class extends Command {
1338
+ constructor([key, cursor, opts], cmdOpts) {
1339
+ const command = ["zscan", key, cursor];
1340
+ if (opts?.match) {
1341
+ command.push("match", opts.match);
1342
+ }
1343
+ if (typeof opts?.count === "number") {
1344
+ command.push("count", opts.count);
1345
+ }
1346
+ super(command, cmdOpts);
1347
+ }
1348
+ };
1349
+
1350
+ // pkg/commands/zscore.ts
1351
+ var ZScoreCommand = class extends Command {
1352
+ constructor(cmd, opts) {
1353
+ super(["zscore", ...cmd], opts);
1354
+ }
1355
+ };
1356
+
1357
+ // pkg/commands/zunion.ts
1358
+ var ZUnionCommand = class extends Command {
1359
+ constructor([numKeys, keyOrKeys, opts], cmdOpts) {
1360
+ const command = ["zunion", numKeys];
1361
+ if (Array.isArray(keyOrKeys)) {
1362
+ command.push(...keyOrKeys);
1363
+ } else {
1364
+ command.push(keyOrKeys);
1365
+ }
1366
+ if (opts) {
1367
+ if ("weights" in opts && opts.weights) {
1368
+ command.push("weights", ...opts.weights);
1369
+ } else if ("weight" in opts && typeof opts.weight === "number") {
1370
+ command.push("weights", opts.weight);
1371
+ }
1372
+ if ("aggregate" in opts) {
1373
+ command.push("aggregate", opts.aggregate);
1374
+ }
1375
+ if (opts?.withScores) {
1376
+ command.push("withscores");
1377
+ }
1378
+ }
1379
+ super(command, cmdOpts);
1380
+ }
1381
+ };
1382
+
1383
+ // pkg/commands/zunionstore.ts
1384
+ var ZUnionStoreCommand = class extends Command {
1385
+ constructor([destination, numKeys, keyOrKeys, opts], cmdOpts) {
1386
+ const command = ["zunionstore", destination, numKeys];
1387
+ if (Array.isArray(keyOrKeys)) {
1388
+ command.push(...keyOrKeys);
1389
+ } else {
1390
+ command.push(keyOrKeys);
1391
+ }
1392
+ if (opts) {
1393
+ if ("weights" in opts && opts.weights) {
1394
+ command.push("weights", ...opts.weights);
1395
+ } else if ("weight" in opts && typeof opts.weight === "number") {
1396
+ command.push("weights", opts.weight);
1397
+ }
1398
+ if ("aggregate" in opts) {
1399
+ command.push("aggregate", opts.aggregate);
1400
+ }
1401
+ }
1402
+ super(command, cmdOpts);
1403
+ }
1404
+ };
1405
+
1406
+ // pkg/commands/xadd.ts
1407
+ var XAddCommand = class extends Command {
1408
+ constructor([key, id, entries, opts], commandOptions) {
1409
+ const command = ["XADD", key];
1410
+ if (opts) {
1411
+ if (opts.nomkStream) {
1412
+ command.push("NOMKSTREAM");
1413
+ }
1414
+ if (opts.trim) {
1415
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
1416
+ if (typeof opts.trim.limit !== "undefined") {
1417
+ command.push("LIMIT", opts.trim.limit);
1418
+ }
1419
+ }
1420
+ }
1421
+ command.push(id);
1422
+ Object.entries(entries).forEach(([k, v]) => {
1423
+ command.push(k, v);
1424
+ });
1425
+ super(command, commandOptions);
1426
+ }
1427
+ };
1428
+
1429
+ // pkg/commands/xrange.ts
1430
+ function deserialize4(result) {
1431
+ const obj = {};
1432
+ for (const e of result) {
1433
+ while (e.length >= 2) {
1434
+ const streamId = e.shift();
1435
+ const entries = e.shift();
1436
+ if (!(streamId in obj)) {
1437
+ obj[streamId] = {};
1438
+ }
1439
+ while (entries.length >= 2) {
1440
+ const field = entries.shift();
1441
+ const value = entries.shift();
1442
+ try {
1443
+ obj[streamId][field] = JSON.parse(value);
1444
+ } catch {
1445
+ obj[streamId][field] = value;
1446
+ }
1447
+ }
1448
+ }
1449
+ }
1450
+ return obj;
1451
+ }
1452
+ var XRangeCommand = class extends Command {
1453
+ constructor([key, start, end, count], opts) {
1454
+ const command = ["XRANGE", key, start, end];
1455
+ if (typeof count === "number") {
1456
+ command.push("COUNT", count);
1457
+ }
1458
+ super(command, {
1459
+ deserialize: (result) => deserialize4(result),
1460
+ ...opts
1461
+ });
1462
+ }
1463
+ };
1464
+
1465
+ // pkg/commands/zmscore.ts
1466
+ var ZMScoreCommand = class extends Command {
1467
+ constructor(cmd, opts) {
1468
+ const [key, members] = cmd;
1469
+ super(["zmscore", key, ...members], opts);
1470
+ }
1471
+ };
1472
+
1473
+ // pkg/commands/zdiffstore.ts
1474
+ var ZDiffStoreCommand = class extends Command {
1475
+ constructor(cmd, opts) {
1476
+ super(["zdiffstore", ...cmd], opts);
1477
+ }
1478
+ };
1479
+
1480
+ // pkg/pipeline.ts
1481
+ var Pipeline = class {
1482
+ client;
1483
+ commands;
1484
+ commandOptions;
1485
+ multiExec;
1486
+ constructor(opts) {
1487
+ this.client = opts.client;
1488
+ this.commands = [];
1489
+ this.commandOptions = opts.commandOptions;
1490
+ this.multiExec = opts.multiExec ?? false;
1491
+ }
1492
+ /**
1493
+ * Send the pipeline request to upstash.
1494
+ *
1495
+ * Returns an array with the results of all pipelined commands.
1496
+ *
1497
+ * If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:
1498
+ * ```ts
1499
+ * const p = redis.pipeline()
1500
+ * p.get("key")
1501
+ * const result = p.exec<[{ greeting: string }]>()
1502
+ * ```
1503
+ */
1504
+ exec = async () => {
1505
+ if (this.commands.length === 0) {
1506
+ throw new Error("Pipeline is empty");
1507
+ }
1508
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
1509
+ const res = await this.client.request({
1510
+ path,
1511
+ body: Object.values(this.commands).map((c) => c.command)
1512
+ });
1513
+ return res.map(({ error, result }, i) => {
1514
+ if (error) {
1515
+ throw new UpstashError(
1516
+ `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`
1517
+ );
1518
+ }
1519
+ return this.commands[i].deserialize(result);
1520
+ });
1521
+ };
1522
+ /**
1523
+ * Returns the length of pipeline before the execution
1524
+ */
1525
+ length() {
1526
+ return this.commands.length;
1527
+ }
1528
+ /**
1529
+ * Pushes a command into the pipeline and returns a chainable instance of the
1530
+ * pipeline
1531
+ */
1532
+ chain(command) {
1533
+ this.commands.push(command);
1534
+ return this;
1535
+ }
1536
+ /**
1537
+ * @see https://redis.io/commands/append
1538
+ */
1539
+ append = (...args) => this.chain(new AppendCommand(args, this.commandOptions));
1540
+ /**
1541
+ * @see https://redis.io/commands/bitcount
1542
+ */
1543
+ bitcount = (...args) => this.chain(new BitCountCommand(args, this.commandOptions));
1544
+ /**
1545
+ * @see https://redis.io/commands/bitop
1546
+ */
1547
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => this.chain(
1548
+ new BitOpCommand(
1549
+ [op, destinationKey, sourceKey, ...sourceKeys],
1550
+ this.commandOptions
1551
+ )
1552
+ );
1553
+ /**
1554
+ * @see https://redis.io/commands/bitpos
1555
+ */
1556
+ bitpos = (...args) => this.chain(new BitPosCommand(args, this.commandOptions));
1557
+ /**
1558
+ * @see https://redis.io/commands/zdiffstore
1559
+ */
1560
+ zdiffstore = (...args) => this.chain(new ZDiffStoreCommand(args, this.commandOptions));
1561
+ /**
1562
+ * @see https://redis.io/commands/dbsize
1563
+ */
1564
+ dbsize = () => this.chain(new DBSizeCommand(this.commandOptions));
1565
+ /**
1566
+ * @see https://redis.io/commands/decr
1567
+ */
1568
+ decr = (...args) => this.chain(new DecrCommand(args, this.commandOptions));
1569
+ /**
1570
+ * @see https://redis.io/commands/decrby
1571
+ */
1572
+ decrby = (...args) => this.chain(new DecrByCommand(args, this.commandOptions));
1573
+ /**
1574
+ * @see https://redis.io/commands/del
1575
+ */
1576
+ del = (...args) => this.chain(new DelCommand(args, this.commandOptions));
1577
+ /**
1578
+ * @see https://redis.io/commands/echo
1579
+ */
1580
+ echo = (...args) => this.chain(new EchoCommand(args, this.commandOptions));
1581
+ /**
1582
+ * @see https://redis.io/commands/eval
1583
+ */
1584
+ eval = (...args) => this.chain(new EvalCommand(args, this.commandOptions));
1585
+ /**
1586
+ * @see https://redis.io/commands/evalsha
1587
+ */
1588
+ evalsha = (...args) => this.chain(new EvalshaCommand(args, this.commandOptions));
1589
+ /**
1590
+ * @see https://redis.io/commands/exists
1591
+ */
1592
+ exists = (...args) => this.chain(new ExistsCommand(args, this.commandOptions));
1593
+ /**
1594
+ * @see https://redis.io/commands/expire
1595
+ */
1596
+ expire = (...args) => this.chain(new ExpireCommand(args, this.commandOptions));
1597
+ /**
1598
+ * @see https://redis.io/commands/expireat
1599
+ */
1600
+ expireat = (...args) => this.chain(new ExpireAtCommand(args, this.commandOptions));
1601
+ /**
1602
+ * @see https://redis.io/commands/flushall
1603
+ */
1604
+ flushall = (args) => this.chain(new FlushAllCommand(args, this.commandOptions));
1605
+ /**
1606
+ * @see https://redis.io/commands/flushdb
1607
+ */
1608
+ flushdb = (...args) => this.chain(new FlushDBCommand(args, this.commandOptions));
1609
+ /**
1610
+ * @see https://redis.io/commands/get
1611
+ */
1612
+ get = (...args) => this.chain(new GetCommand(args, this.commandOptions));
1613
+ /**
1614
+ * @see https://redis.io/commands/getbit
1615
+ */
1616
+ getbit = (...args) => this.chain(new GetBitCommand(args, this.commandOptions));
1617
+ /**
1618
+ * @see https://redis.io/commands/getdel
1619
+ */
1620
+ getdel = (...args) => this.chain(new GetDelCommand(args, this.commandOptions));
1621
+ /**
1622
+ * @see https://redis.io/commands/getrange
1623
+ */
1624
+ getrange = (...args) => this.chain(new GetRangeCommand(args, this.commandOptions));
1625
+ /**
1626
+ * @see https://redis.io/commands/getset
1627
+ */
1628
+ getset = (key, value) => this.chain(new GetSetCommand([key, value], this.commandOptions));
1629
+ /**
1630
+ * @see https://redis.io/commands/hdel
1631
+ */
1632
+ hdel = (...args) => this.chain(new HDelCommand(args, this.commandOptions));
1633
+ /**
1634
+ * @see https://redis.io/commands/hexists
1635
+ */
1636
+ hexists = (...args) => this.chain(new HExistsCommand(args, this.commandOptions));
1637
+ /**
1638
+ * @see https://redis.io/commands/hget
1639
+ */
1640
+ hget = (...args) => this.chain(new HGetCommand(args, this.commandOptions));
1641
+ /**
1642
+ * @see https://redis.io/commands/hgetall
1643
+ */
1644
+ hgetall = (...args) => this.chain(new HGetAllCommand(args, this.commandOptions));
1645
+ /**
1646
+ * @see https://redis.io/commands/hincrby
1647
+ */
1648
+ hincrby = (...args) => this.chain(new HIncrByCommand(args, this.commandOptions));
1649
+ /**
1650
+ * @see https://redis.io/commands/hincrbyfloat
1651
+ */
1652
+ hincrbyfloat = (...args) => this.chain(new HIncrByFloatCommand(args, this.commandOptions));
1653
+ /**
1654
+ * @see https://redis.io/commands/hkeys
1655
+ */
1656
+ hkeys = (...args) => this.chain(new HKeysCommand(args, this.commandOptions));
1657
+ /**
1658
+ * @see https://redis.io/commands/hlen
1659
+ */
1660
+ hlen = (...args) => this.chain(new HLenCommand(args, this.commandOptions));
1661
+ /**
1662
+ * @see https://redis.io/commands/hmget
1663
+ */
1664
+ hmget = (...args) => this.chain(new HMGetCommand(args, this.commandOptions));
1665
+ /**
1666
+ * @see https://redis.io/commands/hmset
1667
+ */
1668
+ hmset = (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions));
1669
+ /**
1670
+ * @see https://redis.io/commands/hrandfield
1671
+ */
1672
+ hrandfield = (key, count, withValues) => this.chain(
1673
+ new HRandFieldCommand(
1674
+ [key, count, withValues],
1675
+ this.commandOptions
1676
+ )
1677
+ );
1678
+ /**
1679
+ * @see https://redis.io/commands/hscan
1680
+ */
1681
+ hscan = (...args) => this.chain(new HScanCommand(args, this.commandOptions));
1682
+ /**
1683
+ * @see https://redis.io/commands/hset
1684
+ */
1685
+ hset = (key, kv) => this.chain(new HSetCommand([key, kv], this.commandOptions));
1686
+ /**
1687
+ * @see https://redis.io/commands/hsetnx
1688
+ */
1689
+ hsetnx = (key, field, value) => this.chain(
1690
+ new HSetNXCommand([key, field, value], this.commandOptions)
1691
+ );
1692
+ /**
1693
+ * @see https://redis.io/commands/hstrlen
1694
+ */
1695
+ hstrlen = (...args) => this.chain(new HStrLenCommand(args, this.commandOptions));
1696
+ /**
1697
+ * @see https://redis.io/commands/hvals
1698
+ */
1699
+ hvals = (...args) => this.chain(new HValsCommand(args, this.commandOptions));
1700
+ /**
1701
+ * @see https://redis.io/commands/incr
1702
+ */
1703
+ incr = (...args) => this.chain(new IncrCommand(args, this.commandOptions));
1704
+ /**
1705
+ * @see https://redis.io/commands/incrby
1706
+ */
1707
+ incrby = (...args) => this.chain(new IncrByCommand(args, this.commandOptions));
1708
+ /**
1709
+ * @see https://redis.io/commands/incrbyfloat
1710
+ */
1711
+ incrbyfloat = (...args) => this.chain(new IncrByFloatCommand(args, this.commandOptions));
1712
+ /**
1713
+ * @see https://redis.io/commands/keys
1714
+ */
1715
+ keys = (...args) => this.chain(new KeysCommand(args, this.commandOptions));
1716
+ /**
1717
+ * @see https://redis.io/commands/lindex
1718
+ */
1719
+ lindex = (...args) => this.chain(new LIndexCommand(args, this.commandOptions));
1720
+ /**
1721
+ * @see https://redis.io/commands/linsert
1722
+ */
1723
+ linsert = (key, direction, pivot, value) => this.chain(
1724
+ new LInsertCommand(
1725
+ [key, direction, pivot, value],
1726
+ this.commandOptions
1727
+ )
1728
+ );
1729
+ /**
1730
+ * @see https://redis.io/commands/llen
1731
+ */
1732
+ llen = (...args) => this.chain(new LLenCommand(args, this.commandOptions));
1733
+ /**
1734
+ * @see https://redis.io/commands/lmove
1735
+ */
1736
+ lmove = (...args) => this.chain(new LMoveCommand(args, this.commandOptions));
1737
+ /**
1738
+ * @see https://redis.io/commands/lpop
1739
+ */
1740
+ lpop = (...args) => this.chain(new LPopCommand(args, this.commandOptions));
1741
+ /**
1742
+ * @see https://redis.io/commands/lpos
1743
+ */
1744
+ lpos = (...args) => this.chain(new LPosCommand(args, this.commandOptions));
1745
+ /**
1746
+ * @see https://redis.io/commands/lpush
1747
+ */
1748
+ lpush = (key, ...elements) => this.chain(
1749
+ new LPushCommand([key, ...elements], this.commandOptions)
1750
+ );
1751
+ /**
1752
+ * @see https://redis.io/commands/lpushx
1753
+ */
1754
+ lpushx = (key, ...elements) => this.chain(
1755
+ new LPushXCommand([key, ...elements], this.commandOptions)
1756
+ );
1757
+ /**
1758
+ * @see https://redis.io/commands/lrange
1759
+ */
1760
+ lrange = (...args) => this.chain(new LRangeCommand(args, this.commandOptions));
1761
+ /**
1762
+ * @see https://redis.io/commands/lrem
1763
+ */
1764
+ lrem = (key, count, value) => this.chain(new LRemCommand([key, count, value], this.commandOptions));
1765
+ /**
1766
+ * @see https://redis.io/commands/lset
1767
+ */
1768
+ lset = (key, index, value) => this.chain(new LSetCommand([key, index, value], this.commandOptions));
1769
+ /**
1770
+ * @see https://redis.io/commands/ltrim
1771
+ */
1772
+ ltrim = (...args) => this.chain(new LTrimCommand(args, this.commandOptions));
1773
+ /**
1774
+ * @see https://redis.io/commands/mget
1775
+ */
1776
+ mget = (...args) => this.chain(new MGetCommand(args, this.commandOptions));
1777
+ /**
1778
+ * @see https://redis.io/commands/mset
1779
+ */
1780
+ mset = (kv) => this.chain(new MSetCommand([kv], this.commandOptions));
1781
+ /**
1782
+ * @see https://redis.io/commands/msetnx
1783
+ */
1784
+ msetnx = (kv) => this.chain(new MSetNXCommand([kv], this.commandOptions));
1785
+ /**
1786
+ * @see https://redis.io/commands/persist
1787
+ */
1788
+ persist = (...args) => this.chain(new PersistCommand(args, this.commandOptions));
1789
+ /**
1790
+ * @see https://redis.io/commands/pexpire
1791
+ */
1792
+ pexpire = (...args) => this.chain(new PExpireCommand(args, this.commandOptions));
1793
+ /**
1794
+ * @see https://redis.io/commands/pexpireat
1795
+ */
1796
+ pexpireat = (...args) => this.chain(new PExpireAtCommand(args, this.commandOptions));
1797
+ /**
1798
+ * @see https://redis.io/commands/ping
1799
+ */
1800
+ ping = (args) => this.chain(new PingCommand(args, this.commandOptions));
1801
+ /**
1802
+ * @see https://redis.io/commands/psetex
1803
+ */
1804
+ psetex = (key, ttl, value) => this.chain(
1805
+ new PSetEXCommand([key, ttl, value], this.commandOptions)
1806
+ );
1807
+ /**
1808
+ * @see https://redis.io/commands/pttl
1809
+ */
1810
+ pttl = (...args) => this.chain(new PTtlCommand(args, this.commandOptions));
1811
+ /**
1812
+ * @see https://redis.io/commands/publish
1813
+ */
1814
+ publish = (...args) => this.chain(new PublishCommand(args, this.commandOptions));
1815
+ /**
1816
+ * @see https://redis.io/commands/randomkey
1817
+ */
1818
+ randomkey = () => this.chain(new RandomKeyCommand(this.commandOptions));
1819
+ /**
1820
+ * @see https://redis.io/commands/rename
1821
+ */
1822
+ rename = (...args) => this.chain(new RenameCommand(args, this.commandOptions));
1823
+ /**
1824
+ * @see https://redis.io/commands/renamenx
1825
+ */
1826
+ renamenx = (...args) => this.chain(new RenameNXCommand(args, this.commandOptions));
1827
+ /**
1828
+ * @see https://redis.io/commands/rpop
1829
+ */
1830
+ rpop = (...args) => this.chain(new RPopCommand(args, this.commandOptions));
1831
+ /**
1832
+ * @see https://redis.io/commands/rpush
1833
+ */
1834
+ rpush = (key, ...elements) => this.chain(new RPushCommand([key, ...elements], this.commandOptions));
1835
+ /**
1836
+ * @see https://redis.io/commands/rpushx
1837
+ */
1838
+ rpushx = (key, ...elements) => this.chain(new RPushXCommand([key, ...elements], this.commandOptions));
1839
+ /**
1840
+ * @see https://redis.io/commands/sadd
1841
+ */
1842
+ sadd = (key, ...members) => this.chain(new SAddCommand([key, ...members], this.commandOptions));
1843
+ /**
1844
+ * @see https://redis.io/commands/scan
1845
+ */
1846
+ scan = (...args) => this.chain(new ScanCommand(args, this.commandOptions));
1847
+ /**
1848
+ * @see https://redis.io/commands/scard
1849
+ */
1850
+ scard = (...args) => this.chain(new SCardCommand(args, this.commandOptions));
1851
+ /**
1852
+ * @see https://redis.io/commands/script-exists
1853
+ */
1854
+ scriptExists = (...args) => this.chain(new ScriptExistsCommand(args, this.commandOptions));
1855
+ /**
1856
+ * @see https://redis.io/commands/script-flush
1857
+ */
1858
+ scriptFlush = (...args) => this.chain(new ScriptFlushCommand(args, this.commandOptions));
1859
+ /**
1860
+ * @see https://redis.io/commands/script-load
1861
+ */
1862
+ scriptLoad = (...args) => this.chain(new ScriptLoadCommand(args, this.commandOptions));
1863
+ /*)*
1864
+ * @see https://redis.io/commands/sdiff
1865
+ */
1866
+ sdiff = (...args) => this.chain(new SDiffCommand(args, this.commandOptions));
1867
+ /**
1868
+ * @see https://redis.io/commands/sdiffstore
1869
+ */
1870
+ sdiffstore = (...args) => this.chain(new SDiffStoreCommand(args, this.commandOptions));
1871
+ /**
1872
+ * @see https://redis.io/commands/set
1873
+ */
1874
+ set = (key, value, opts) => this.chain(new SetCommand([key, value, opts], this.commandOptions));
1875
+ /**
1876
+ * @see https://redis.io/commands/setbit
1877
+ */
1878
+ setbit = (...args) => this.chain(new SetBitCommand(args, this.commandOptions));
1879
+ /**
1880
+ * @see https://redis.io/commands/setex
1881
+ */
1882
+ setex = (key, ttl, value) => this.chain(new SetExCommand([key, ttl, value], this.commandOptions));
1883
+ /**
1884
+ * @see https://redis.io/commands/setnx
1885
+ */
1886
+ setnx = (key, value) => this.chain(new SetNxCommand([key, value], this.commandOptions));
1887
+ /**
1888
+ * @see https://redis.io/commands/setrange
1889
+ */
1890
+ setrange = (...args) => this.chain(new SetRangeCommand(args, this.commandOptions));
1891
+ /**
1892
+ * @see https://redis.io/commands/sinter
1893
+ */
1894
+ sinter = (...args) => this.chain(new SInterCommand(args, this.commandOptions));
1895
+ /**
1896
+ * @see https://redis.io/commands/sinterstore
1897
+ */
1898
+ sinterstore = (...args) => this.chain(new SInterStoreCommand(args, this.commandOptions));
1899
+ /**
1900
+ * @see https://redis.io/commands/sismember
1901
+ */
1902
+ sismember = (key, member) => this.chain(new SIsMemberCommand([key, member], this.commandOptions));
1903
+ /**
1904
+ * @see https://redis.io/commands/smembers
1905
+ */
1906
+ smembers = (...args) => this.chain(new SMembersCommand(args, this.commandOptions));
1907
+ /**
1908
+ * @see https://redis.io/commands/smismember
1909
+ */
1910
+ smismember = (key, members) => this.chain(
1911
+ new SMIsMemberCommand([key, members], this.commandOptions)
1912
+ );
1913
+ /**
1914
+ * @see https://redis.io/commands/smove
1915
+ */
1916
+ smove = (source, destination, member) => this.chain(
1917
+ new SMoveCommand(
1918
+ [source, destination, member],
1919
+ this.commandOptions
1920
+ )
1921
+ );
1922
+ /**
1923
+ * @see https://redis.io/commands/spop
1924
+ */
1925
+ spop = (...args) => this.chain(new SPopCommand(args, this.commandOptions));
1926
+ /**
1927
+ * @see https://redis.io/commands/srandmember
1928
+ */
1929
+ srandmember = (...args) => this.chain(new SRandMemberCommand(args, this.commandOptions));
1930
+ /**
1931
+ * @see https://redis.io/commands/srem
1932
+ */
1933
+ srem = (key, ...members) => this.chain(new SRemCommand([key, ...members], this.commandOptions));
1934
+ /**
1935
+ * @see https://redis.io/commands/sscan
1936
+ */
1937
+ sscan = (...args) => this.chain(new SScanCommand(args, this.commandOptions));
1938
+ /**
1939
+ * @see https://redis.io/commands/strlen
1940
+ */
1941
+ strlen = (...args) => this.chain(new StrLenCommand(args, this.commandOptions));
1942
+ /**
1943
+ * @see https://redis.io/commands/sunion
1944
+ */
1945
+ sunion = (...args) => this.chain(new SUnionCommand(args, this.commandOptions));
1946
+ /**
1947
+ * @see https://redis.io/commands/sunionstore
1948
+ */
1949
+ sunionstore = (...args) => this.chain(new SUnionStoreCommand(args, this.commandOptions));
1950
+ /**
1951
+ * @see https://redis.io/commands/time
1952
+ */
1953
+ time = () => this.chain(new TimeCommand(this.commandOptions));
1954
+ /**
1955
+ * @see https://redis.io/commands/touch
1956
+ */
1957
+ touch = (...args) => this.chain(new TouchCommand(args, this.commandOptions));
1958
+ /**
1959
+ * @see https://redis.io/commands/ttl
1960
+ */
1961
+ ttl = (...args) => this.chain(new TtlCommand(args, this.commandOptions));
1962
+ /**
1963
+ * @see https://redis.io/commands/type
1964
+ */
1965
+ type = (...args) => this.chain(new TypeCommand(args, this.commandOptions));
1966
+ /**
1967
+ * @see https://redis.io/commands/unlink
1968
+ */
1969
+ unlink = (...args) => this.chain(new UnlinkCommand(args, this.commandOptions));
1970
+ /**
1971
+ * @see https://redis.io/commands/zadd
1972
+ */
1973
+ zadd = (...args) => {
1974
+ if ("score" in args[1]) {
1975
+ return this.chain(
1976
+ new ZAddCommand(
1977
+ [args[0], args[1], ...args.slice(2)],
1978
+ this.commandOptions
1979
+ )
1980
+ );
1981
+ }
1982
+ return this.chain(
1983
+ new ZAddCommand(
1984
+ [args[0], args[1], ...args.slice(2)],
1985
+ this.commandOptions
1986
+ )
1987
+ );
1988
+ };
1989
+ /**
1990
+ * @see https://redis.io/commands/zcard
1991
+ */
1992
+ zcard = (...args) => this.chain(new ZCardCommand(args, this.commandOptions));
1993
+ /**
1994
+ * @see https://redis.io/commands/zcount
1995
+ */
1996
+ zcount = (...args) => this.chain(new ZCountCommand(args, this.commandOptions));
1997
+ /**
1998
+ * @see https://redis.io/commands/zincrby
1999
+ */
2000
+ zincrby = (key, increment, member) => this.chain(
2001
+ new ZIncrByCommand([key, increment, member], this.commandOptions)
2002
+ );
2003
+ /**
2004
+ * @see https://redis.io/commands/zinterstore
2005
+ */
2006
+ zinterstore = (...args) => this.chain(new ZInterStoreCommand(args, this.commandOptions));
2007
+ /**
2008
+ * @see https://redis.io/commands/zlexcount
2009
+ */
2010
+ zlexcount = (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions));
2011
+ /**
2012
+ * @see https://redis.io/commands/zmscore
2013
+ */
2014
+ zmscore = (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions));
2015
+ /**
2016
+ * @see https://redis.io/commands/zpopmax
2017
+ */
2018
+ zpopmax = (...args) => this.chain(new ZPopMaxCommand(args, this.commandOptions));
2019
+ /**
2020
+ * @see https://redis.io/commands/zpopmin
2021
+ */
2022
+ zpopmin = (...args) => this.chain(new ZPopMinCommand(args, this.commandOptions));
2023
+ /**
2024
+ * @see https://redis.io/commands/zrange
2025
+ */
2026
+ zrange = (...args) => this.chain(new ZRangeCommand(args, this.commandOptions));
2027
+ /**
2028
+ * @see https://redis.io/commands/zrank
2029
+ */
2030
+ zrank = (key, member) => this.chain(new ZRankCommand([key, member], this.commandOptions));
2031
+ /**
2032
+ * @see https://redis.io/commands/zrem
2033
+ */
2034
+ zrem = (key, ...members) => this.chain(new ZRemCommand([key, ...members], this.commandOptions));
2035
+ /**
2036
+ * @see https://redis.io/commands/zremrangebylex
2037
+ */
2038
+ zremrangebylex = (...args) => this.chain(new ZRemRangeByLexCommand(args, this.commandOptions));
2039
+ /**
2040
+ * @see https://redis.io/commands/zremrangebyrank
2041
+ */
2042
+ zremrangebyrank = (...args) => this.chain(new ZRemRangeByRankCommand(args, this.commandOptions));
2043
+ /**
2044
+ * @see https://redis.io/commands/zremrangebyscore
2045
+ */
2046
+ zremrangebyscore = (...args) => this.chain(new ZRemRangeByScoreCommand(args, this.commandOptions));
2047
+ /**
2048
+ * @see https://redis.io/commands/zrevrank
2049
+ */
2050
+ zrevrank = (key, member) => this.chain(new ZRevRankCommand([key, member], this.commandOptions));
2051
+ /**
2052
+ * @see https://redis.io/commands/zscan
2053
+ */
2054
+ zscan = (...args) => this.chain(new ZScanCommand(args, this.commandOptions));
2055
+ /**
2056
+ * @see https://redis.io/commands/zscore
2057
+ */
2058
+ zscore = (key, member) => this.chain(new ZScoreCommand([key, member], this.commandOptions));
2059
+ /**
2060
+ * @see https://redis.io/commands/zunionstore
2061
+ */
2062
+ zunionstore = (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions));
2063
+ /**
2064
+ * @see https://redis.io/commands/zunion
2065
+ */
2066
+ zunion = (...args) => this.chain(new ZUnionCommand(args, this.commandOptions));
2067
+ /**
2068
+ * @see https://redis.io/commands/?group=json
2069
+ */
2070
+ get json() {
2071
+ return {
2072
+ /**
2073
+ * @see https://redis.io/commands/json.arrappend
2074
+ */
2075
+ arrappend: (...args) => this.chain(new JsonArrAppendCommand(args, this.commandOptions)),
2076
+ /**
2077
+ * @see https://redis.io/commands/json.arrindex
2078
+ */
2079
+ arrindex: (...args) => this.chain(new JsonArrIndexCommand(args, this.commandOptions)),
2080
+ /**
2081
+ * @see https://redis.io/commands/json.arrinsert
2082
+ */
2083
+ arrinsert: (...args) => this.chain(new JsonArrInsertCommand(args, this.commandOptions)),
2084
+ /**
2085
+ * @see https://redis.io/commands/json.arrlen
2086
+ */
2087
+ arrlen: (...args) => this.chain(new JsonArrLenCommand(args, this.commandOptions)),
2088
+ /**
2089
+ * @see https://redis.io/commands/json.arrpop
2090
+ */
2091
+ arrpop: (...args) => this.chain(new JsonArrPopCommand(args, this.commandOptions)),
2092
+ /**
2093
+ * @see https://redis.io/commands/json.arrtrim
2094
+ */
2095
+ arrtrim: (...args) => this.chain(new JsonArrTrimCommand(args, this.commandOptions)),
2096
+ /**
2097
+ * @see https://redis.io/commands/json.clear
2098
+ */
2099
+ clear: (...args) => this.chain(new JsonClearCommand(args, this.commandOptions)),
2100
+ /**
2101
+ * @see https://redis.io/commands/json.del
2102
+ */
2103
+ del: (...args) => this.chain(new JsonDelCommand(args, this.commandOptions)),
2104
+ /**
2105
+ * @see https://redis.io/commands/json.forget
2106
+ */
2107
+ forget: (...args) => this.chain(new JsonForgetCommand(args, this.commandOptions)),
2108
+ /**
2109
+ * @see https://redis.io/commands/json.get
2110
+ */
2111
+ get: (...args) => this.chain(new JsonGetCommand(args, this.commandOptions)),
2112
+ /**
2113
+ * @see https://redis.io/commands/json.mget
2114
+ */
2115
+ mget: (...args) => this.chain(new JsonMGetCommand(args, this.commandOptions)),
2116
+ /**
2117
+ * @see https://redis.io/commands/json.numincrby
2118
+ */
2119
+ numincrby: (...args) => this.chain(new JsonNumIncrByCommand(args, this.commandOptions)),
2120
+ /**
2121
+ * @see https://redis.io/commands/json.nummultby
2122
+ */
2123
+ nummultby: (...args) => this.chain(new JsonNumMultByCommand(args, this.commandOptions)),
2124
+ /**
2125
+ * @see https://redis.io/commands/json.objkeys
2126
+ */
2127
+ objkeys: (...args) => this.chain(new JsonObjKeysCommand(args, this.commandOptions)),
2128
+ /**
2129
+ * @see https://redis.io/commands/json.objlen
2130
+ */
2131
+ objlen: (...args) => this.chain(new JsonObjLenCommand(args, this.commandOptions)),
2132
+ /**
2133
+ * @see https://redis.io/commands/json.resp
2134
+ */
2135
+ resp: (...args) => this.chain(new JsonRespCommand(args, this.commandOptions)),
2136
+ /**
2137
+ * @see https://redis.io/commands/json.set
2138
+ */
2139
+ set: (...args) => this.chain(new JsonSetCommand(args, this.commandOptions)),
2140
+ /**
2141
+ * @see https://redis.io/commands/json.strappend
2142
+ */
2143
+ strappend: (...args) => this.chain(new JsonStrAppendCommand(args, this.commandOptions)),
2144
+ /**
2145
+ * @see https://redis.io/commands/json.strlen
2146
+ */
2147
+ strlen: (...args) => this.chain(new JsonStrLenCommand(args, this.commandOptions)),
2148
+ /**
2149
+ * @see https://redis.io/commands/json.toggle
2150
+ */
2151
+ toggle: (...args) => this.chain(new JsonToggleCommand(args, this.commandOptions)),
2152
+ /**
2153
+ * @see https://redis.io/commands/json.type
2154
+ */
2155
+ type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
2156
+ };
2157
+ }
2158
+ };
2159
+
2160
+ // pkg/script.ts
2161
+ var Script = class {
2162
+ script;
2163
+ sha1;
2164
+ redis;
2165
+ constructor(redis, script) {
2166
+ this.redis = redis;
2167
+ this.sha1 = this.digest(script);
2168
+ this.script = script;
2169
+ }
2170
+ /**
2171
+ * Send an `EVAL` command to redis.
2172
+ */
2173
+ async eval(keys, args) {
2174
+ return await this.redis.eval(this.script, keys, args);
2175
+ }
2176
+ /**
2177
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
2178
+ */
2179
+ async evalsha(keys, args) {
2180
+ return await this.redis.evalsha(this.sha1, keys, args);
2181
+ }
2182
+ /**
2183
+ * Optimistically try to run `EVALSHA` first.
2184
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
2185
+ *
2186
+ * Following calls will be able to use the cached script
2187
+ */
2188
+ async exec(keys, args) {
2189
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(
2190
+ async (err) => {
2191
+ if (err instanceof Error && err.message.toLowerCase().includes("noscript")) {
2192
+ return await this.redis.eval(this.script, keys, args);
2193
+ }
2194
+ throw err;
2195
+ }
2196
+ );
2197
+ return res;
2198
+ }
2199
+ /**
2200
+ * Compute the sha1 hash of the script and return its hex representation.
2201
+ */
2202
+ digest(s) {
2203
+ const hash = new Bun.CryptoHasher("sha1").update(s).digest("hex");
2204
+ return typeof hash === "string" ? hash : new TextDecoder().decode(hash);
2205
+ }
2206
+ };
2207
+
2208
+ // pkg/redis.ts
2209
+ var Redis = class {
2210
+ client;
2211
+ opts;
2212
+ enableTelemetry;
2213
+ /**
2214
+ * Create a new redis client
2215
+ *
2216
+ * @example
2217
+ * ```typescript
2218
+ * const redis = new Redis({
2219
+ * url: "<UPSTASH_REDIS_REST_URL>",
2220
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
2221
+ * });
2222
+ * ```
2223
+ */
2224
+ constructor(client, opts) {
2225
+ this.client = client;
2226
+ this.opts = opts;
2227
+ this.enableTelemetry = opts?.enableTelemetry ?? true;
2228
+ }
2229
+ get json() {
2230
+ return {
2231
+ /**
2232
+ * @see https://redis.io/commands/json.arrappend
2233
+ */
2234
+ arrappend: (...args) => new JsonArrAppendCommand(args, this.opts).exec(this.client),
2235
+ /**
2236
+ * @see https://redis.io/commands/json.arrindex
2237
+ */
2238
+ arrindex: (...args) => new JsonArrIndexCommand(args, this.opts).exec(this.client),
2239
+ /**
2240
+ * @see https://redis.io/commands/json.arrinsert
2241
+ */
2242
+ arrinsert: (...args) => new JsonArrInsertCommand(args, this.opts).exec(this.client),
2243
+ /**
2244
+ * @see https://redis.io/commands/json.arrlen
2245
+ */
2246
+ arrlen: (...args) => new JsonArrLenCommand(args, this.opts).exec(this.client),
2247
+ /**
2248
+ * @see https://redis.io/commands/json.arrpop
2249
+ */
2250
+ arrpop: (...args) => new JsonArrPopCommand(args, this.opts).exec(this.client),
2251
+ /**
2252
+ * @see https://redis.io/commands/json.arrtrim
2253
+ */
2254
+ arrtrim: (...args) => new JsonArrTrimCommand(args, this.opts).exec(this.client),
2255
+ /**
2256
+ * @see https://redis.io/commands/json.clear
2257
+ */
2258
+ clear: (...args) => new JsonClearCommand(args, this.opts).exec(this.client),
2259
+ /**
2260
+ * @see https://redis.io/commands/json.del
2261
+ */
2262
+ del: (...args) => new JsonDelCommand(args, this.opts).exec(this.client),
2263
+ /**
2264
+ * @see https://redis.io/commands/json.forget
2265
+ */
2266
+ forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
2267
+ /**
2268
+ * @see https://redis.io/commands/geoadd
2269
+ */
2270
+ geoadd: (...args) => new GeoAddCommand(args, this.opts).exec(this.client),
2271
+ /**
2272
+ * @see https://redis.io/commands/json.get
2273
+ */
2274
+ get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
2275
+ /**
2276
+ * @see https://redis.io/commands/json.mget
2277
+ */
2278
+ mget: (...args) => new JsonMGetCommand(args, this.opts).exec(this.client),
2279
+ /**
2280
+ * @see https://redis.io/commands/json.numincrby
2281
+ */
2282
+ numincrby: (...args) => new JsonNumIncrByCommand(args, this.opts).exec(this.client),
2283
+ /**
2284
+ * @see https://redis.io/commands/json.nummultby
2285
+ */
2286
+ nummultby: (...args) => new JsonNumMultByCommand(args, this.opts).exec(this.client),
2287
+ /**
2288
+ * @see https://redis.io/commands/json.objkeys
2289
+ */
2290
+ objkeys: (...args) => new JsonObjKeysCommand(args, this.opts).exec(this.client),
2291
+ /**
2292
+ * @see https://redis.io/commands/json.objlen
2293
+ */
2294
+ objlen: (...args) => new JsonObjLenCommand(args, this.opts).exec(this.client),
2295
+ /**
2296
+ * @see https://redis.io/commands/json.resp
2297
+ */
2298
+ resp: (...args) => new JsonRespCommand(args, this.opts).exec(this.client),
2299
+ /**
2300
+ * @see https://redis.io/commands/json.set
2301
+ */
2302
+ set: (...args) => new JsonSetCommand(args, this.opts).exec(this.client),
2303
+ /**
2304
+ * @see https://redis.io/commands/json.strappend
2305
+ */
2306
+ strappend: (...args) => new JsonStrAppendCommand(args, this.opts).exec(this.client),
2307
+ /**
2308
+ * @see https://redis.io/commands/json.strlen
2309
+ */
2310
+ strlen: (...args) => new JsonStrLenCommand(args, this.opts).exec(this.client),
2311
+ /**
2312
+ * @see https://redis.io/commands/json.toggle
2313
+ */
2314
+ toggle: (...args) => new JsonToggleCommand(args, this.opts).exec(this.client),
2315
+ /**
2316
+ * @see https://redis.io/commands/json.type
2317
+ */
2318
+ type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
2319
+ };
2320
+ }
2321
+ /**
2322
+ * Wrap a new middleware around the HTTP client.
2323
+ */
2324
+ use = (middleware) => {
2325
+ const makeRequest = this.client.request.bind(this.client);
2326
+ this.client.request = (req) => middleware(req, makeRequest);
2327
+ };
2328
+ /**
2329
+ * Technically this is not private, we can hide it from intellisense by doing this
2330
+ */
2331
+ addTelemetry = (telemetry) => {
2332
+ if (!this.enableTelemetry) {
2333
+ return;
2334
+ }
2335
+ try {
2336
+ this.client.mergeTelemetry(telemetry);
2337
+ } catch {
2338
+ }
2339
+ };
2340
+ createScript(script) {
2341
+ return new Script(this, script);
2342
+ }
2343
+ /**
2344
+ * Create a new pipeline that allows you to send requests in bulk.
2345
+ *
2346
+ * @see {@link Pipeline}
2347
+ */
2348
+ pipeline = () => new Pipeline({
2349
+ client: this.client,
2350
+ commandOptions: this.opts,
2351
+ multiExec: false
2352
+ });
2353
+ /**
2354
+ * Create a new transaction to allow executing multiple steps atomically.
2355
+ *
2356
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
2357
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
2358
+ * guarantees that the commands are executed as a single isolated operation.
2359
+ *
2360
+ * @see {@link Pipeline}
2361
+ */
2362
+ multi = () => new Pipeline({
2363
+ client: this.client,
2364
+ commandOptions: this.opts,
2365
+ multiExec: true
2366
+ });
2367
+ /**
2368
+ * @see https://redis.io/commands/append
2369
+ */
2370
+ append = (...args) => new AppendCommand(args, this.opts).exec(this.client);
2371
+ /**
2372
+ * @see https://redis.io/commands/bitcount
2373
+ */
2374
+ bitcount = (...args) => new BitCountCommand(args, this.opts).exec(this.client);
2375
+ /**
2376
+ * @see https://redis.io/commands/bitop
2377
+ */
2378
+ bitop = (op, destinationKey, sourceKey, ...sourceKeys) => new BitOpCommand(
2379
+ [op, destinationKey, sourceKey, ...sourceKeys],
2380
+ this.opts
2381
+ ).exec(this.client);
2382
+ /**
2383
+ * @see https://redis.io/commands/bitpos
2384
+ */
2385
+ bitpos = (...args) => new BitPosCommand(args, this.opts).exec(this.client);
2386
+ /**
2387
+ * @see https://redis.io/commands/dbsize
2388
+ */
2389
+ dbsize = () => new DBSizeCommand(this.opts).exec(this.client);
2390
+ /**
2391
+ * @see https://redis.io/commands/decr
2392
+ */
2393
+ decr = (...args) => new DecrCommand(args, this.opts).exec(this.client);
2394
+ /**
2395
+ * @see https://redis.io/commands/decrby
2396
+ */
2397
+ decrby = (...args) => new DecrByCommand(args, this.opts).exec(this.client);
2398
+ /**
2399
+ * @see https://redis.io/commands/del
2400
+ */
2401
+ del = (...args) => new DelCommand(args, this.opts).exec(this.client);
2402
+ /**
2403
+ * @see https://redis.io/commands/echo
2404
+ */
2405
+ echo = (...args) => new EchoCommand(args, this.opts).exec(this.client);
2406
+ /**
2407
+ * @see https://redis.io/commands/eval
2408
+ */
2409
+ eval = (...args) => new EvalCommand(args, this.opts).exec(this.client);
2410
+ /**
2411
+ * @see https://redis.io/commands/evalsha
2412
+ */
2413
+ evalsha = (...args) => new EvalshaCommand(args, this.opts).exec(this.client);
2414
+ /**
2415
+ * @see https://redis.io/commands/exists
2416
+ */
2417
+ exists = (...args) => new ExistsCommand(args, this.opts).exec(this.client);
2418
+ /**
2419
+ * @see https://redis.io/commands/expire
2420
+ */
2421
+ expire = (...args) => new ExpireCommand(args, this.opts).exec(this.client);
2422
+ /**
2423
+ * @see https://redis.io/commands/expireat
2424
+ */
2425
+ expireat = (...args) => new ExpireAtCommand(args, this.opts).exec(this.client);
2426
+ /**
2427
+ * @see https://redis.io/commands/flushall
2428
+ */
2429
+ flushall = (args) => new FlushAllCommand(args, this.opts).exec(this.client);
2430
+ /**
2431
+ * @see https://redis.io/commands/flushdb
2432
+ */
2433
+ flushdb = (...args) => new FlushDBCommand(args, this.opts).exec(this.client);
2434
+ /**
2435
+ * @see https://redis.io/commands/get
2436
+ */
2437
+ get = (...args) => new GetCommand(args, this.opts).exec(this.client);
2438
+ /**
2439
+ * @see https://redis.io/commands/getbit
2440
+ */
2441
+ getbit = (...args) => new GetBitCommand(args, this.opts).exec(this.client);
2442
+ /**
2443
+ * @see https://redis.io/commands/getdel
2444
+ */
2445
+ getdel = (...args) => new GetDelCommand(args, this.opts).exec(this.client);
2446
+ /**
2447
+ * @see https://redis.io/commands/getrange
2448
+ */
2449
+ getrange = (...args) => new GetRangeCommand(args, this.opts).exec(this.client);
2450
+ /**
2451
+ * @see https://redis.io/commands/getset
2452
+ */
2453
+ getset = (key, value) => new GetSetCommand([key, value], this.opts).exec(this.client);
2454
+ /**
2455
+ * @see https://redis.io/commands/hdel
2456
+ */
2457
+ hdel = (...args) => new HDelCommand(args, this.opts).exec(this.client);
2458
+ /**
2459
+ * @see https://redis.io/commands/hexists
2460
+ */
2461
+ hexists = (...args) => new HExistsCommand(args, this.opts).exec(this.client);
2462
+ /**
2463
+ * @see https://redis.io/commands/hget
2464
+ */
2465
+ hget = (...args) => new HGetCommand(args, this.opts).exec(this.client);
2466
+ /**
2467
+ * @see https://redis.io/commands/hgetall
2468
+ */
2469
+ hgetall = (...args) => new HGetAllCommand(args, this.opts).exec(this.client);
2470
+ /**
2471
+ * @see https://redis.io/commands/hincrby
2472
+ */
2473
+ hincrby = (...args) => new HIncrByCommand(args, this.opts).exec(this.client);
2474
+ /**
2475
+ * @see https://redis.io/commands/hincrbyfloat
2476
+ */
2477
+ hincrbyfloat = (...args) => new HIncrByFloatCommand(args, this.opts).exec(this.client);
2478
+ /**
2479
+ * @see https://redis.io/commands/hkeys
2480
+ */
2481
+ hkeys = (...args) => new HKeysCommand(args, this.opts).exec(this.client);
2482
+ /**
2483
+ * @see https://redis.io/commands/hlen
2484
+ */
2485
+ hlen = (...args) => new HLenCommand(args, this.opts).exec(this.client);
2486
+ /**
2487
+ * @see https://redis.io/commands/hmget
2488
+ */
2489
+ hmget = (...args) => new HMGetCommand(args, this.opts).exec(this.client);
2490
+ /**
2491
+ * @see https://redis.io/commands/hmset
2492
+ */
2493
+ hmset = (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client);
2494
+ /**
2495
+ * @see https://redis.io/commands/hrandfield
2496
+ */
2497
+ hrandfield = (key, count, withValues) => new HRandFieldCommand(
2498
+ [key, count, withValues],
2499
+ this.opts
2500
+ ).exec(this.client);
2501
+ /**
2502
+ * @see https://redis.io/commands/hscan
2503
+ */
2504
+ hscan = (...args) => new HScanCommand(args, this.opts).exec(this.client);
2505
+ /**
2506
+ * @see https://redis.io/commands/hset
2507
+ */
2508
+ hset = (key, kv) => new HSetCommand([key, kv], this.opts).exec(this.client);
2509
+ /**
2510
+ * @see https://redis.io/commands/hsetnx
2511
+ */
2512
+ hsetnx = (key, field, value) => new HSetNXCommand([key, field, value], this.opts).exec(this.client);
2513
+ /**
2514
+ * @see https://redis.io/commands/hstrlen
2515
+ */
2516
+ hstrlen = (...args) => new HStrLenCommand(args, this.opts).exec(this.client);
2517
+ /**
2518
+ * @see https://redis.io/commands/hvals
2519
+ */
2520
+ hvals = (...args) => new HValsCommand(args, this.opts).exec(this.client);
2521
+ /**
2522
+ * @see https://redis.io/commands/incr
2523
+ */
2524
+ incr = (...args) => new IncrCommand(args, this.opts).exec(this.client);
2525
+ /**
2526
+ * @see https://redis.io/commands/incrby
2527
+ */
2528
+ incrby = (...args) => new IncrByCommand(args, this.opts).exec(this.client);
2529
+ /**
2530
+ * @see https://redis.io/commands/incrbyfloat
2531
+ */
2532
+ incrbyfloat = (...args) => new IncrByFloatCommand(args, this.opts).exec(this.client);
2533
+ /**
2534
+ * @see https://redis.io/commands/keys
2535
+ */
2536
+ keys = (...args) => new KeysCommand(args, this.opts).exec(this.client);
2537
+ /**
2538
+ * @see https://redis.io/commands/lindex
2539
+ */
2540
+ lindex = (...args) => new LIndexCommand(args, this.opts).exec(this.client);
2541
+ /**
2542
+ * @see https://redis.io/commands/linsert
2543
+ */
2544
+ linsert = (key, direction, pivot, value) => new LInsertCommand([key, direction, pivot, value], this.opts).exec(
2545
+ this.client
2546
+ );
2547
+ /**
2548
+ * @see https://redis.io/commands/llen
2549
+ */
2550
+ llen = (...args) => new LLenCommand(args, this.opts).exec(this.client);
2551
+ /**
2552
+ * @see https://redis.io/commands/lmove
2553
+ */
2554
+ lmove = (...args) => new LMoveCommand(args, this.opts).exec(this.client);
2555
+ /**
2556
+ * @see https://redis.io/commands/lpop
2557
+ */
2558
+ lpop = (...args) => new LPopCommand(args, this.opts).exec(this.client);
2559
+ /**
2560
+ * @see https://redis.io/commands/lpos
2561
+ */
2562
+ lpos = (...args) => new LPosCommand(args, this.opts).exec(this.client);
2563
+ /**
2564
+ * @see https://redis.io/commands/lpush
2565
+ */
2566
+ lpush = (key, ...elements) => new LPushCommand([key, ...elements], this.opts).exec(this.client);
2567
+ /**
2568
+ * @see https://redis.io/commands/lpushx
2569
+ */
2570
+ lpushx = (key, ...elements) => new LPushXCommand([key, ...elements], this.opts).exec(this.client);
2571
+ /**
2572
+ * @see https://redis.io/commands/lrange
2573
+ */
2574
+ lrange = (...args) => new LRangeCommand(args, this.opts).exec(this.client);
2575
+ /**
2576
+ * @see https://redis.io/commands/lrem
2577
+ */
2578
+ lrem = (key, count, value) => new LRemCommand([key, count, value], this.opts).exec(this.client);
2579
+ /**
2580
+ * @see https://redis.io/commands/lset
2581
+ */
2582
+ lset = (key, index, value) => new LSetCommand([key, index, value], this.opts).exec(this.client);
2583
+ /**
2584
+ * @see https://redis.io/commands/ltrim
2585
+ */
2586
+ ltrim = (...args) => new LTrimCommand(args, this.opts).exec(this.client);
2587
+ /**
2588
+ * @see https://redis.io/commands/mget
2589
+ */
2590
+ mget = (...args) => new MGetCommand(args, this.opts).exec(this.client);
2591
+ /**
2592
+ * @see https://redis.io/commands/mset
2593
+ */
2594
+ mset = (kv) => new MSetCommand([kv], this.opts).exec(this.client);
2595
+ /**
2596
+ * @see https://redis.io/commands/msetnx
2597
+ */
2598
+ msetnx = (kv) => new MSetNXCommand([kv], this.opts).exec(this.client);
2599
+ /**
2600
+ * @see https://redis.io/commands/persist
2601
+ */
2602
+ persist = (...args) => new PersistCommand(args, this.opts).exec(this.client);
2603
+ /**
2604
+ * @see https://redis.io/commands/pexpire
2605
+ */
2606
+ pexpire = (...args) => new PExpireCommand(args, this.opts).exec(this.client);
2607
+ /**
2608
+ * @see https://redis.io/commands/pexpireat
2609
+ */
2610
+ pexpireat = (...args) => new PExpireAtCommand(args, this.opts).exec(this.client);
2611
+ /**
2612
+ * @see https://redis.io/commands/ping
2613
+ */
2614
+ ping = (args) => new PingCommand(args, this.opts).exec(this.client);
2615
+ /**
2616
+ * @see https://redis.io/commands/psetex
2617
+ */
2618
+ psetex = (key, ttl, value) => new PSetEXCommand([key, ttl, value], this.opts).exec(this.client);
2619
+ /**
2620
+ * @see https://redis.io/commands/pttl
2621
+ */
2622
+ pttl = (...args) => new PTtlCommand(args, this.opts).exec(this.client);
2623
+ /**
2624
+ * @see https://redis.io/commands/publish
2625
+ */
2626
+ publish = (...args) => new PublishCommand(args, this.opts).exec(this.client);
2627
+ /**
2628
+ * @see https://redis.io/commands/randomkey
2629
+ */
2630
+ randomkey = () => new RandomKeyCommand().exec(this.client);
2631
+ /**
2632
+ * @see https://redis.io/commands/rename
2633
+ */
2634
+ rename = (...args) => new RenameCommand(args, this.opts).exec(this.client);
2635
+ /**
2636
+ * @see https://redis.io/commands/renamenx
2637
+ */
2638
+ renamenx = (...args) => new RenameNXCommand(args, this.opts).exec(this.client);
2639
+ /**
2640
+ * @see https://redis.io/commands/rpop
2641
+ */
2642
+ rpop = (...args) => new RPopCommand(args, this.opts).exec(this.client);
2643
+ /**
2644
+ * @see https://redis.io/commands/rpush
2645
+ */
2646
+ rpush = (key, ...elements) => new RPushCommand([key, ...elements], this.opts).exec(this.client);
2647
+ /**
2648
+ * @see https://redis.io/commands/rpushx
2649
+ */
2650
+ rpushx = (key, ...elements) => new RPushXCommand([key, ...elements], this.opts).exec(this.client);
2651
+ /**
2652
+ * @see https://redis.io/commands/sadd
2653
+ */
2654
+ sadd = (key, ...members) => new SAddCommand([key, ...members], this.opts).exec(this.client);
2655
+ /**
2656
+ * @see https://redis.io/commands/scan
2657
+ */
2658
+ scan = (...args) => new ScanCommand(args, this.opts).exec(this.client);
2659
+ /**
2660
+ * @see https://redis.io/commands/scard
2661
+ */
2662
+ scard = (...args) => new SCardCommand(args, this.opts).exec(this.client);
2663
+ /**
2664
+ * @see https://redis.io/commands/script-exists
2665
+ */
2666
+ scriptExists = (...args) => new ScriptExistsCommand(args, this.opts).exec(this.client);
2667
+ /**
2668
+ * @see https://redis.io/commands/script-flush
2669
+ */
2670
+ scriptFlush = (...args) => new ScriptFlushCommand(args, this.opts).exec(this.client);
2671
+ /**
2672
+ * @see https://redis.io/commands/script-load
2673
+ */
2674
+ scriptLoad = (...args) => new ScriptLoadCommand(args, this.opts).exec(this.client);
2675
+ /**
2676
+ * @see https://redis.io/commands/sdiff
2677
+ */
2678
+ sdiff = (...args) => new SDiffCommand(args, this.opts).exec(this.client);
2679
+ /**
2680
+ * @see https://redis.io/commands/sdiffstore
2681
+ */
2682
+ sdiffstore = (...args) => new SDiffStoreCommand(args, this.opts).exec(this.client);
2683
+ /**
2684
+ * @see https://redis.io/commands/set
2685
+ */
2686
+ set = (key, value, opts) => new SetCommand([key, value, opts], this.opts).exec(this.client);
2687
+ /**
2688
+ * @see https://redis.io/commands/setbit
2689
+ */
2690
+ setbit = (...args) => new SetBitCommand(args, this.opts).exec(this.client);
2691
+ /**
2692
+ * @see https://redis.io/commands/setex
2693
+ */
2694
+ setex = (key, ttl, value) => new SetExCommand([key, ttl, value], this.opts).exec(this.client);
2695
+ /**
2696
+ * @see https://redis.io/commands/setnx
2697
+ */
2698
+ setnx = (key, value) => new SetNxCommand([key, value], this.opts).exec(this.client);
2699
+ /**
2700
+ * @see https://redis.io/commands/setrange
2701
+ */
2702
+ setrange = (...args) => new SetRangeCommand(args, this.opts).exec(this.client);
2703
+ /**
2704
+ * @see https://redis.io/commands/sinter
2705
+ */
2706
+ sinter = (...args) => new SInterCommand(args, this.opts).exec(this.client);
2707
+ /**
2708
+ * @see https://redis.io/commands/sinterstore
2709
+ */
2710
+ sinterstore = (...args) => new SInterStoreCommand(args, this.opts).exec(this.client);
2711
+ /**
2712
+ * @see https://redis.io/commands/sismember
2713
+ */
2714
+ sismember = (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client);
2715
+ /**
2716
+ * @see https://redis.io/commands/smismember
2717
+ */
2718
+ smismember = (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(
2719
+ this.client
2720
+ );
2721
+ /**
2722
+ * @see https://redis.io/commands/smembers
2723
+ */
2724
+ smembers = (...args) => new SMembersCommand(args, this.opts).exec(this.client);
2725
+ /**
2726
+ * @see https://redis.io/commands/smove
2727
+ */
2728
+ smove = (source, destination, member) => new SMoveCommand([source, destination, member], this.opts).exec(
2729
+ this.client
2730
+ );
2731
+ /**
2732
+ * @see https://redis.io/commands/spop
2733
+ */
2734
+ spop = (...args) => new SPopCommand(args, this.opts).exec(this.client);
2735
+ /**
2736
+ * @see https://redis.io/commands/srandmember
2737
+ */
2738
+ srandmember = (...args) => new SRandMemberCommand(args, this.opts).exec(this.client);
2739
+ /**
2740
+ * @see https://redis.io/commands/srem
2741
+ */
2742
+ srem = (key, ...members) => new SRemCommand([key, ...members], this.opts).exec(this.client);
2743
+ /**
2744
+ * @see https://redis.io/commands/sscan
2745
+ */
2746
+ sscan = (...args) => new SScanCommand(args, this.opts).exec(this.client);
2747
+ /**
2748
+ * @see https://redis.io/commands/strlen
2749
+ */
2750
+ strlen = (...args) => new StrLenCommand(args, this.opts).exec(this.client);
2751
+ /**
2752
+ * @see https://redis.io/commands/sunion
2753
+ */
2754
+ sunion = (...args) => new SUnionCommand(args, this.opts).exec(this.client);
2755
+ /**
2756
+ * @see https://redis.io/commands/sunionstore
2757
+ */
2758
+ sunionstore = (...args) => new SUnionStoreCommand(args, this.opts).exec(this.client);
2759
+ /**
2760
+ * @see https://redis.io/commands/time
2761
+ */
2762
+ time = () => new TimeCommand().exec(this.client);
2763
+ /**
2764
+ * @see https://redis.io/commands/touch
2765
+ */
2766
+ touch = (...args) => new TouchCommand(args, this.opts).exec(this.client);
2767
+ /**
2768
+ * @see https://redis.io/commands/ttl
2769
+ */
2770
+ ttl = (...args) => new TtlCommand(args, this.opts).exec(this.client);
2771
+ /**
2772
+ * @see https://redis.io/commands/type
2773
+ */
2774
+ type = (...args) => new TypeCommand(args, this.opts).exec(this.client);
2775
+ /**
2776
+ * @see https://redis.io/commands/unlink
2777
+ */
2778
+ unlink = (...args) => new UnlinkCommand(args, this.opts).exec(this.client);
2779
+ /**
2780
+ * @see https://redis.io/commands/xadd
2781
+ */
2782
+ xadd = (...args) => new XAddCommand(args, this.opts).exec(this.client);
2783
+ /**
2784
+ * @see https://redis.io/commands/xrange
2785
+ */
2786
+ xrange = (...args) => new XRangeCommand(args, this.opts).exec(this.client);
2787
+ /**
2788
+ * @see https://redis.io/commands/zadd
2789
+ */
2790
+ zadd = (...args) => {
2791
+ if ("score" in args[1]) {
2792
+ return new ZAddCommand(
2793
+ [args[0], args[1], ...args.slice(2)],
2794
+ this.opts
2795
+ ).exec(this.client);
2796
+ }
2797
+ return new ZAddCommand(
2798
+ [args[0], args[1], ...args.slice(2)],
2799
+ this.opts
2800
+ ).exec(this.client);
2801
+ };
2802
+ /**
2803
+ * @see https://redis.io/commands/zcard
2804
+ */
2805
+ zcard = (...args) => new ZCardCommand(args, this.opts).exec(this.client);
2806
+ /**
2807
+ * @see https://redis.io/commands/zcount
2808
+ */
2809
+ zcount = (...args) => new ZCountCommand(args, this.opts).exec(this.client);
2810
+ /**
2811
+ * @see https://redis.io/commands/zdiffstore
2812
+ */
2813
+ zdiffstore = (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client);
2814
+ /**
2815
+ * @see https://redis.io/commands/zincrby
2816
+ */
2817
+ zincrby = (key, increment, member) => new ZIncrByCommand([key, increment, member], this.opts).exec(
2818
+ this.client
2819
+ );
2820
+ /**
2821
+ * @see https://redis.io/commands/zinterstore
2822
+ */
2823
+ zinterstore = (...args) => new ZInterStoreCommand(args, this.opts).exec(this.client);
2824
+ /**
2825
+ * @see https://redis.io/commands/zlexcount
2826
+ */
2827
+ zlexcount = (...args) => new ZLexCountCommand(args, this.opts).exec(this.client);
2828
+ /**
2829
+ * @see https://redis.io/commands/zmscore
2830
+ */
2831
+ zmscore = (...args) => new ZMScoreCommand(args, this.opts).exec(this.client);
2832
+ /**
2833
+ * @see https://redis.io/commands/zpopmax
2834
+ */
2835
+ zpopmax = (...args) => new ZPopMaxCommand(args, this.opts).exec(this.client);
2836
+ /**
2837
+ * @see https://redis.io/commands/zpopmin
2838
+ */
2839
+ zpopmin = (...args) => new ZPopMinCommand(args, this.opts).exec(this.client);
2840
+ /**
2841
+ * @see https://redis.io/commands/zrange
2842
+ */
2843
+ zrange = (...args) => new ZRangeCommand(args, this.opts).exec(this.client);
2844
+ /**
2845
+ * @see https://redis.io/commands/zrank
2846
+ */
2847
+ zrank = (key, member) => new ZRankCommand([key, member], this.opts).exec(this.client);
2848
+ /**
2849
+ * @see https://redis.io/commands/zrem
2850
+ */
2851
+ zrem = (key, ...members) => new ZRemCommand([key, ...members], this.opts).exec(this.client);
2852
+ /**
2853
+ * @see https://redis.io/commands/zremrangebylex
2854
+ */
2855
+ zremrangebylex = (...args) => new ZRemRangeByLexCommand(args, this.opts).exec(this.client);
2856
+ /**
2857
+ * @see https://redis.io/commands/zremrangebyrank
2858
+ */
2859
+ zremrangebyrank = (...args) => new ZRemRangeByRankCommand(args, this.opts).exec(this.client);
2860
+ /**
2861
+ * @see https://redis.io/commands/zremrangebyscore
2862
+ */
2863
+ zremrangebyscore = (...args) => new ZRemRangeByScoreCommand(args, this.opts).exec(this.client);
2864
+ /**
2865
+ * @see https://redis.io/commands/zrevrank
2866
+ */
2867
+ zrevrank = (key, member) => new ZRevRankCommand([key, member], this.opts).exec(this.client);
2868
+ /**
2869
+ * @see https://redis.io/commands/zscan
2870
+ */
2871
+ zscan = (...args) => new ZScanCommand(args, this.opts).exec(this.client);
2872
+ /**
2873
+ * @see https://redis.io/commands/zscore
2874
+ */
2875
+ zscore = (key, member) => new ZScoreCommand([key, member], this.opts).exec(this.client);
2876
+ /**
2877
+ * @see https://redis.io/commands/zunion
2878
+ */
2879
+ zunion = (...args) => new ZUnionCommand(args, this.opts).exec(this.client);
2880
+ /**
2881
+ * @see https://redis.io/commands/zunionstore
2882
+ */
2883
+ zunionstore = (...args) => new ZUnionStoreCommand(args, this.opts).exec(this.client);
2884
+ };
2885
+
2886
+ // pkg/http.ts
2887
+ var HttpClient = class {
2888
+ baseUrl;
2889
+ headers;
2890
+ options;
2891
+ retry;
2892
+ constructor(config) {
2893
+ this.options = {
2894
+ backend: config.options?.backend,
2895
+ agent: config.agent,
2896
+ responseEncoding: config.responseEncoding ?? "base64",
2897
+ // default to base64
2898
+ cache: config.cache
2899
+ };
2900
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
2901
+ this.headers = {
2902
+ "Content-Type": "application/json",
2903
+ ...config.headers
2904
+ };
2905
+ if (this.options.responseEncoding === "base64") {
2906
+ this.headers["Upstash-Encoding"] = "base64";
2907
+ }
2908
+ if (typeof config?.retry === "boolean" && config?.retry === false) {
2909
+ this.retry = {
2910
+ attempts: 1,
2911
+ backoff: () => 0
2912
+ };
2913
+ } else {
2914
+ this.retry = {
2915
+ attempts: config?.retry?.retries ?? 5,
2916
+ backoff: config?.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50)
2917
+ };
2918
+ }
2919
+ }
2920
+ mergeTelemetry(telemetry) {
2921
+ function merge(obj, key, value) {
2922
+ if (!value) {
2923
+ return obj;
2924
+ }
2925
+ if (obj[key]) {
2926
+ obj[key] = [obj[key], value].join(",");
2927
+ } else {
2928
+ obj[key] = value;
2929
+ }
2930
+ return obj;
2931
+ }
2932
+ this.headers = merge(
2933
+ this.headers,
2934
+ "Upstash-Telemetry-Runtime",
2935
+ telemetry.runtime
2936
+ );
2937
+ this.headers = merge(
2938
+ this.headers,
2939
+ "Upstash-Telemetry-Platform",
2940
+ telemetry.platform
2941
+ );
2942
+ this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
2943
+ }
2944
+ async request(req) {
2945
+ const requestOptions = {
2946
+ cache: this.options.cache,
2947
+ method: "POST",
2948
+ headers: this.headers,
2949
+ body: JSON.stringify(req.body),
2950
+ keepalive: true,
2951
+ agent: this.options?.agent,
2952
+ /**
2953
+ * Fastly specific
2954
+ */
2955
+ backend: this.options?.backend
2956
+ };
2957
+ let res = null;
2958
+ let error = null;
2959
+ for (let i = 0; i <= this.retry.attempts; i++) {
2960
+ try {
2961
+ res = await fetch(
2962
+ [this.baseUrl, ...req.path ?? []].join("/"),
2963
+ requestOptions
2964
+ );
2965
+ break;
2966
+ } catch (err) {
2967
+ error = err;
2968
+ await new Promise((r) => setTimeout(r, this.retry.backoff(i)));
2969
+ }
2970
+ }
2971
+ if (!res) {
2972
+ throw error ?? new Error("Exhausted all retries");
2973
+ }
2974
+ const body = await res.json();
2975
+ if (!res.ok) {
2976
+ throw new UpstashError(
2977
+ `${body.error}, command was: ${JSON.stringify(req.body)}`
2978
+ );
2979
+ }
2980
+ if (this.options?.responseEncoding === "base64") {
2981
+ if (Array.isArray(body)) {
2982
+ return body.map(({ result: result2, error: error2 }) => ({
2983
+ result: decode(result2),
2984
+ error: error2
2985
+ }));
2986
+ }
2987
+ const result = decode(body.result);
2988
+ return { result, error: body.error };
2989
+ }
2990
+ return body;
2991
+ }
2992
+ };
2993
+ function base64decode(b64) {
2994
+ let dec = "";
2995
+ try {
2996
+ const binString = atob(b64);
2997
+ const size = binString.length;
2998
+ const bytes = new Uint8Array(size);
2999
+ for (let i = 0; i < size; i++) {
3000
+ bytes[i] = binString.charCodeAt(i);
3001
+ }
3002
+ dec = new TextDecoder().decode(bytes);
3003
+ } catch {
3004
+ dec = b64;
3005
+ }
3006
+ return dec;
3007
+ }
3008
+ function decode(raw) {
3009
+ let result = void 0;
3010
+ switch (typeof raw) {
3011
+ case "undefined":
3012
+ return raw;
3013
+ case "number": {
3014
+ result = raw;
3015
+ break;
3016
+ }
3017
+ case "object": {
3018
+ if (Array.isArray(raw)) {
3019
+ result = raw.map(
3020
+ (v) => typeof v === "string" ? base64decode(v) : Array.isArray(v) ? v.map(decode) : v
3021
+ );
3022
+ } else {
3023
+ result = null;
3024
+ }
3025
+ break;
3026
+ }
3027
+ case "string": {
3028
+ result = raw === "OK" ? "OK" : base64decode(raw);
3029
+ break;
3030
+ }
3031
+ default:
3032
+ break;
3033
+ }
3034
+ return result;
3035
+ }
3036
+
3037
+ // version.ts
3038
+ var VERSION = "v0.0.0";
3039
+
3040
+ // platforms/fastly.ts
3041
+ var Redis2 = class extends Redis {
3042
+ /**
3043
+ * Create a new redis client
3044
+ *
3045
+ * @example
3046
+ * ```typescript
3047
+ * const redis = new Redis({
3048
+ * url: "<UPSTASH_REDIS_REST_URL>",
3049
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
3050
+ * backend: "upstash-db",
3051
+ * });
3052
+ * ```
3053
+ */
3054
+ constructor(config) {
3055
+ if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
3056
+ console.warn(
3057
+ "The redis url contains whitespace or newline, which can cause errors!"
3058
+ );
3059
+ }
3060
+ if (config.token.startsWith(" ") || config.token.endsWith(" ") || /\r|\n/.test(config.token)) {
3061
+ console.warn(
3062
+ "The redis token contains whitespace or newline, which can cause errors!"
3063
+ );
3064
+ }
3065
+ const client = new HttpClient({
3066
+ baseUrl: config.url,
3067
+ retry: config.retry,
3068
+ headers: { authorization: `Bearer ${config.token}` },
3069
+ options: { backend: config.backend },
3070
+ responseEncoding: config.responseEncoding
3071
+ });
3072
+ super(client, {
3073
+ automaticDeserialization: config.automaticDeserialization
3074
+ });
3075
+ this.addTelemetry({
3076
+ sdk: `@upstash/redis@${VERSION}`,
3077
+ platform: "fastly"
3078
+ });
3079
+ }
3080
+ };
3081
+ // Annotate the CommonJS export names for ESM import in node:
3082
+ 0 && (module.exports = {
3083
+ Redis
3084
+ });
3085
+ //# sourceMappingURL=fastly.js.map