@upstash/redis 0.0.0-ci.e475de1f85007c6e91b7c723aae0092693599d18-20231218001438 → 0.0.0-ci.e4eab2833c7196d06833dccf8f132ddbc18c2cfa-20241008071408

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