@upstash/redis 0.0.0-ci.fc1b22d0-20231019 → 0.0.0-ci.fd62df5f23c9d3ce31f52781474d711bbed876d2-20231031095501

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