@upstash/redis 0.0.0-ci.fd62df5f23c9d3ce31f52781474d711bbed876d2-20231031095501 → 0.0.0-ci.ff7a0b135b28ff50a7e2634a78123684be3ed71f-20241105152627

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