@upstash/redis 0.0.0-ci.c00b02de3221a40eb48a9e0e9fecd434abda4dc2-20240703080528 → 0.0.0-ci.c21ca079c33c67efb29ee43e778ab181aeed6386-20250530111221

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