@upstash/redis 1.33.1-canary → 1.35.0-canary

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