@upstash/redis 0.0.0-ci.fd62df5f23c9d3ce31f52781474d711bbed876d2-20231031095501 → 0.0.0-ci.fe7ec0544f213f3f58bb19e23dfafafab828c00c-20241107145222

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