@upstash/redis 0.0.0-ci.d9c08accc3bdd7a1d21f3d860e54e9cb1570f23e-20231214113223 → 0.0.0-ci.da1a5cb507eab3a0864199c49d02985f16e8bcd0-20250729064120

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