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