@upstash/redis 0.0.0-ci.b1e842dc-20220903 → 0.0.0-ci.b8efaf97-20230119

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.
Files changed (51) hide show
  1. package/README.md +19 -17
  2. package/esm/pkg/commands/getdel.js +9 -0
  3. package/esm/pkg/commands/hgetall.js +0 -4
  4. package/esm/pkg/commands/hrandfield.js +39 -0
  5. package/esm/pkg/commands/lmove.js +9 -0
  6. package/esm/pkg/commands/mod.js +4 -0
  7. package/esm/pkg/commands/smismember.js +9 -0
  8. package/esm/pkg/commands/zdiffstore.js +9 -0
  9. package/esm/pkg/commands/zmscore.js +1 -1
  10. package/esm/pkg/http.js +99 -2
  11. package/esm/pkg/pipeline.js +61 -6
  12. package/esm/pkg/redis.js +90 -2
  13. package/esm/platforms/cloudflare.js +10 -2
  14. package/esm/platforms/fastly.js +1 -0
  15. package/esm/platforms/node_with_fetch.js +27 -1
  16. package/esm/platforms/nodejs.js +22 -1
  17. package/esm/version.js +1 -0
  18. package/package.json +1 -1
  19. package/script/pkg/commands/getdel.js +13 -0
  20. package/script/pkg/commands/hgetall.js +0 -4
  21. package/script/pkg/commands/hrandfield.js +43 -0
  22. package/script/pkg/commands/lmove.js +13 -0
  23. package/script/pkg/commands/mod.js +4 -0
  24. package/script/pkg/commands/smismember.js +13 -0
  25. package/script/pkg/commands/zdiffstore.js +13 -0
  26. package/script/pkg/commands/zmscore.js +1 -1
  27. package/script/pkg/http.js +99 -2
  28. package/script/pkg/pipeline.js +60 -5
  29. package/script/pkg/redis.js +89 -1
  30. package/script/platforms/cloudflare.js +10 -2
  31. package/script/platforms/fastly.js +1 -0
  32. package/script/platforms/node_with_fetch.js +27 -1
  33. package/script/platforms/nodejs.js +22 -1
  34. package/script/version.js +4 -0
  35. package/types/pkg/commands/getdel.d.ts +7 -0
  36. package/types/pkg/commands/hrandfield.d.ts +9 -0
  37. package/types/pkg/commands/lmove.d.ts +12 -0
  38. package/types/pkg/commands/mod.d.ts +4 -0
  39. package/types/pkg/commands/smembers.d.ts +2 -2
  40. package/types/pkg/commands/smismember.d.ts +7 -0
  41. package/types/pkg/commands/zdiffstore.d.ts +7 -0
  42. package/types/pkg/commands/zmscore.d.ts +1 -1
  43. package/types/pkg/http.d.ts +38 -4
  44. package/types/pkg/pipeline.d.ts +28 -3
  45. package/types/pkg/redis.d.ts +39 -1
  46. package/types/pkg/types.d.ts +17 -0
  47. package/types/platforms/cloudflare.d.ts +8 -7
  48. package/types/platforms/fastly.d.ts +2 -6
  49. package/types/platforms/node_with_fetch.d.ts +2 -21
  50. package/types/platforms/nodejs.d.ts +3 -6
  51. package/types/version.d.ts +1 -0
@@ -1,7 +1,21 @@
1
1
  // deno-lint-ignore-file
2
2
  import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
+ import { VERSION } from "../version.js";
4
5
  import "isomorphic-fetch";
6
+ // @ts-ignore Deno can't compile
7
+ // import https from "https";
8
+ // @ts-ignore Deno can't compile
9
+ // import http from "http";
10
+ // import "isomorphic-fetch";
11
+ /**
12
+ * Workaround for nodejs 14, where atob is not included in the standardlib
13
+ */
14
+ if (typeof atob === "undefined") {
15
+ global.atob = function (b64) {
16
+ return Buffer.from(b64, "base64").toString("utf-8");
17
+ };
18
+ }
5
19
  /**
6
20
  * Serverless redis client for upstash.
7
21
  */
@@ -21,11 +35,23 @@ export class Redis extends core.Redis {
21
35
  /\r|\n/.test(configOrRequester.token)) {
22
36
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
23
37
  }
38
+ const telemetry = {};
39
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
40
+ telemetry.runtime = `node@${process.version}`;
41
+ telemetry.platform = process.env.VERCEL
42
+ ? "vercel"
43
+ : process.env.AWS_REGION
44
+ ? "aws"
45
+ : "unknown";
46
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
47
+ }
24
48
  const client = new HttpClient({
25
49
  baseUrl: configOrRequester.url,
26
50
  retry: configOrRequester.retry,
27
51
  headers: { authorization: `Bearer ${configOrRequester.token}` },
28
- // agent: configOrRequester.agent,
52
+ // agent: configOrRequester.agent,
53
+ responseEncoding: configOrRequester.responseEncoding,
54
+ telemetry,
29
55
  });
30
56
  super(client, {
31
57
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -1,6 +1,15 @@
1
1
  // deno-lint-ignore-file
2
2
  import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
+ import { VERSION } from "../version.js";
5
+ /**
6
+ * Workaround for nodejs 14, where atob is not included in the standardlib
7
+ */
8
+ if (typeof atob === "undefined") {
9
+ global.atob = function (b64) {
10
+ return Buffer.from(b64, "base64").toString("utf-8");
11
+ };
12
+ }
4
13
  /**
5
14
  * Serverless redis client for upstash.
6
15
  */
@@ -20,11 +29,23 @@ export class Redis extends core.Redis {
20
29
  /\r|\n/.test(configOrRequester.token)) {
21
30
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
22
31
  }
32
+ const telemetry = {};
33
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
34
+ telemetry.runtime = `node@${process.version}`;
35
+ telemetry.platform = process.env.VERCEL
36
+ ? "vercel"
37
+ : process.env.AWS_REGION
38
+ ? "aws"
39
+ : "unknown";
40
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
41
+ }
23
42
  const client = new HttpClient({
24
43
  baseUrl: configOrRequester.url,
25
44
  retry: configOrRequester.retry,
26
45
  headers: { authorization: `Bearer ${configOrRequester.token}` },
27
- // agent: configOrRequester.agent,
46
+ agent: configOrRequester.agent,
47
+ responseEncoding: configOrRequester.responseEncoding,
48
+ telemetry,
28
49
  });
29
50
  super(client, {
30
51
  automaticDeserialization: configOrRequester.automaticDeserialization,
package/esm/version.js ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = "v0.0.0-ci.b8efaf97-20230119";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/redis",
6
- "version": "v0.0.0-ci.b1e842dc-20220903",
6
+ "version": "v0.0.0-ci.b8efaf97-20230119",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetDelCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/getdel
7
+ */
8
+ class GetDelCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["getdel", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.GetDelCommand = GetDelCommand;
@@ -2,10 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HGetAllCommand = void 0;
4
4
  const command_js_1 = require("./command.js");
5
- /**
6
- * @param result De
7
- * @returns
8
- */
9
5
  function deserialize(result) {
10
6
  if (result.length === 0) {
11
7
  return null;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HRandFieldCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ function deserialize(result) {
6
+ if (result.length === 0) {
7
+ return null;
8
+ }
9
+ const obj = {};
10
+ while (result.length >= 2) {
11
+ const key = result.shift();
12
+ const value = result.shift();
13
+ try {
14
+ obj[key] = JSON.parse(value);
15
+ }
16
+ catch {
17
+ obj[key] = value;
18
+ }
19
+ }
20
+ return obj;
21
+ }
22
+ /**
23
+ * @see https://redis.io/commands/hrandfield
24
+ */
25
+ class HRandFieldCommand extends command_js_1.Command {
26
+ constructor(cmd, opts) {
27
+ const command = ["hrandfield", cmd[0]];
28
+ if (typeof cmd[1] === "number") {
29
+ command.push(cmd[1]);
30
+ }
31
+ if (cmd[2]) {
32
+ command.push("WITHVALUES");
33
+ }
34
+ super(command, {
35
+ // @ts-ignore TODO:
36
+ deserialize: cmd[2]
37
+ ? (result) => deserialize(result)
38
+ : opts?.deserialize,
39
+ ...opts,
40
+ });
41
+ }
42
+ }
43
+ exports.HRandFieldCommand = HRandFieldCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LMoveCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/lmove
7
+ */
8
+ class LMoveCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["lmove", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.LMoveCommand = LMoveCommand;
@@ -33,11 +33,13 @@ __exportStar(require("./flushall.js"), exports);
33
33
  __exportStar(require("./flushdb.js"), exports);
34
34
  __exportStar(require("./get.js"), exports);
35
35
  __exportStar(require("./getbit.js"), exports);
36
+ __exportStar(require("./getdel.js"), exports);
36
37
  __exportStar(require("./getrange.js"), exports);
37
38
  __exportStar(require("./getset.js"), exports);
38
39
  __exportStar(require("./hdel.js"), exports);
39
40
  __exportStar(require("./hexists.js"), exports);
40
41
  __exportStar(require("./hget.js"), exports);
42
+ __exportStar(require("./smismember.js"), exports);
41
43
  __exportStar(require("./hgetall.js"), exports);
42
44
  __exportStar(require("./hincrby.js"), exports);
43
45
  __exportStar(require("./hincrbyfloat.js"), exports);
@@ -45,6 +47,7 @@ __exportStar(require("./hkeys.js"), exports);
45
47
  __exportStar(require("./hlen.js"), exports);
46
48
  __exportStar(require("./hmget.js"), exports);
47
49
  __exportStar(require("./hmset.js"), exports);
50
+ __exportStar(require("./hrandfield.js"), exports);
48
51
  __exportStar(require("./hscan.js"), exports);
49
52
  __exportStar(require("./hset.js"), exports);
50
53
  __exportStar(require("./hsetnx.js"), exports);
@@ -57,6 +60,7 @@ __exportStar(require("./keys.js"), exports);
57
60
  __exportStar(require("./lindex.js"), exports);
58
61
  __exportStar(require("./linsert.js"), exports);
59
62
  __exportStar(require("./llen.js"), exports);
63
+ __exportStar(require("./lmove.js"), exports);
60
64
  __exportStar(require("./lpop.js"), exports);
61
65
  __exportStar(require("./lpos.js"), exports);
62
66
  __exportStar(require("./lpush.js"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SMIsMemberCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/smismember
7
+ */
8
+ class SMIsMemberCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["smismember", cmd[0], ...cmd[1]], opts);
11
+ }
12
+ }
13
+ exports.SMIsMemberCommand = SMIsMemberCommand;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZDiffStoreCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/zdiffstore
7
+ */
8
+ class ZDiffStoreCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["zdiffstore", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.ZDiffStoreCommand = ZDiffStoreCommand;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZMScoreCommand = void 0;
4
4
  const command_js_1 = require("./command.js");
5
5
  /**
6
- * @see https://redis.io/commands/zscore
6
+ * @see https://redis.io/commands/zmscore
7
7
  */
8
8
  class ZMScoreCommand extends command_js_1.Command {
9
9
  constructor(cmd, opts) {
@@ -28,9 +28,28 @@ class HttpClient {
28
28
  writable: true,
29
29
  value: void 0
30
30
  });
31
+ this.options = {
32
+ backend: config.options?.backend,
33
+ agent: config.agent,
34
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
35
+ };
31
36
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
32
- this.headers = { "Content-Type": "application/json", ...config.headers };
33
- this.options = { backend: config.options?.backend };
37
+ this.headers = {
38
+ "Content-Type": "application/json",
39
+ ...config.headers,
40
+ };
41
+ if (config.telemetry?.runtime) {
42
+ this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
43
+ }
44
+ if (config.telemetry?.platform) {
45
+ this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
46
+ }
47
+ if (config.telemetry?.sdk) {
48
+ this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
49
+ }
50
+ if (this.options.responseEncoding === "base64") {
51
+ this.headers["Upstash-Encoding"] = "base64";
52
+ }
34
53
  if (typeof config?.retry === "boolean" && config?.retry === false) {
35
54
  this.retry = {
36
55
  attempts: 1,
@@ -45,12 +64,30 @@ class HttpClient {
45
64
  };
46
65
  }
47
66
  }
67
+ mergeTelemetry(telemetry) {
68
+ function merge(obj, key, value) {
69
+ if (!value) {
70
+ return obj;
71
+ }
72
+ if (obj[key]) {
73
+ obj[key] = [obj[key], value].join(",");
74
+ }
75
+ else {
76
+ obj[key] = value;
77
+ }
78
+ return obj;
79
+ }
80
+ this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
81
+ this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
82
+ this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
83
+ }
48
84
  async request(req) {
49
85
  const requestOptions = {
50
86
  method: "POST",
51
87
  headers: this.headers,
52
88
  body: JSON.stringify(req.body),
53
89
  keepalive: true,
90
+ agent: this.options?.agent,
54
91
  /**
55
92
  * Fastly specific
56
93
  */
@@ -75,7 +112,67 @@ class HttpClient {
75
112
  if (!res.ok) {
76
113
  throw new error_js_1.UpstashError(body.error);
77
114
  }
115
+ if (this.options?.responseEncoding === "base64") {
116
+ return Array.isArray(body) ? body.map(decode) : decode(body);
117
+ }
78
118
  return body;
79
119
  }
80
120
  }
81
121
  exports.HttpClient = HttpClient;
122
+ function base64decode(b64) {
123
+ let dec = "";
124
+ try {
125
+ /**
126
+ * Using only atob() is not enough because it doesn't work with unicode characters
127
+ */
128
+ const binString = atob(b64);
129
+ const size = binString.length;
130
+ const bytes = new Uint8Array(size);
131
+ for (let i = 0; i < size; i++) {
132
+ bytes[i] = binString.charCodeAt(i);
133
+ }
134
+ dec = new TextDecoder().decode(bytes);
135
+ }
136
+ catch {
137
+ dec = b64;
138
+ }
139
+ return dec;
140
+ // try {
141
+ // return decodeURIComponent(dec);
142
+ // } catch {
143
+ // return dec;
144
+ // }
145
+ }
146
+ function decode(raw) {
147
+ let result = undefined;
148
+ switch (typeof raw.result) {
149
+ case "undefined":
150
+ return raw;
151
+ case "number": {
152
+ result = raw.result;
153
+ break;
154
+ }
155
+ case "object": {
156
+ if (Array.isArray(raw.result)) {
157
+ result = raw.result.map((v) => typeof v === "string"
158
+ ? base64decode(v)
159
+ : Array.isArray(v)
160
+ ? v.map(base64decode)
161
+ : v);
162
+ }
163
+ else {
164
+ // If it's not an array it must be null
165
+ // Apparently null is an object in javascript
166
+ result = null;
167
+ }
168
+ break;
169
+ }
170
+ case "string": {
171
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
172
+ break;
173
+ }
174
+ default:
175
+ break;
176
+ }
177
+ return { result, error: raw.error };
178
+ }
@@ -4,6 +4,8 @@ exports.Pipeline = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const error_js_1 = require("./error.js");
6
6
  const zmscore_js_1 = require("./commands/zmscore.js");
7
+ const hrandfield_js_1 = require("./commands/hrandfield.js");
8
+ const zdiffstore_js_1 = require("./commands/zdiffstore.js");
7
9
  /**
8
10
  * Upstash REST API supports command pipelining to send multiple commands in
9
11
  * batch, instead of sending each command one by one and waiting for a response.
@@ -20,7 +22,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
20
22
  * **Examples:**
21
23
  *
22
24
  * ```ts
23
- * const p = redis.pipeline()
25
+ * const p = redis.pipeline() // or redis.multi()
24
26
  * p.set("key","value")
25
27
  * p.get("key")
26
28
  * const res = await p.exec()
@@ -43,7 +45,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
43
45
  * ```
44
46
  */
45
47
  class Pipeline {
46
- constructor(client, commandOptions) {
48
+ constructor(opts) {
47
49
  Object.defineProperty(this, "client", {
48
50
  enumerable: true,
49
51
  configurable: true,
@@ -62,6 +64,12 @@ class Pipeline {
62
64
  writable: true,
63
65
  value: void 0
64
66
  });
67
+ Object.defineProperty(this, "multiExec", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
65
73
  /**
66
74
  * Send the pipeline request to upstash.
67
75
  *
@@ -80,8 +88,9 @@ class Pipeline {
80
88
  if (this.commands.length === 0) {
81
89
  throw new Error("Pipeline is empty");
82
90
  }
91
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
83
92
  const res = (await this.client.request({
84
- path: ["pipeline"],
93
+ path,
85
94
  body: Object.values(this.commands).map((c) => c.command),
86
95
  }));
87
96
  return res.map(({ error, result }, i) => {
@@ -128,6 +137,15 @@ class Pipeline {
128
137
  writable: true,
129
138
  value: (...args) => this.chain(new mod_js_1.BitPosCommand(args, this.commandOptions))
130
139
  });
140
+ /**
141
+ * @see https://redis.io/commands/zdiffstore
142
+ */
143
+ Object.defineProperty(this, "zdiffstore", {
144
+ enumerable: true,
145
+ configurable: true,
146
+ writable: true,
147
+ value: (...args) => this.chain(new zdiffstore_js_1.ZDiffStoreCommand(args, this.commandOptions))
148
+ });
131
149
  /**
132
150
  * @see https://redis.io/commands/dbsize
133
151
  */
@@ -254,6 +272,15 @@ class Pipeline {
254
272
  writable: true,
255
273
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
256
274
  });
275
+ /**
276
+ * @see https://redis.io/commands/getdel
277
+ */
278
+ Object.defineProperty(this, "getdel", {
279
+ enumerable: true,
280
+ configurable: true,
281
+ writable: true,
282
+ value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
283
+ });
257
284
  /**
258
285
  * @see https://redis.io/commands/getrange
259
286
  */
@@ -362,6 +389,15 @@ class Pipeline {
362
389
  writable: true,
363
390
  value: (key, kv) => this.chain(new mod_js_1.HMSetCommand([key, kv], this.commandOptions))
364
391
  });
392
+ /**
393
+ * @see https://redis.io/commands/hrandfield
394
+ */
395
+ Object.defineProperty(this, "hrandfield", {
396
+ enumerable: true,
397
+ configurable: true,
398
+ writable: true,
399
+ value: (key, count, withValues) => this.chain(new hrandfield_js_1.HRandFieldCommand([key, count, withValues], this.commandOptions))
400
+ });
365
401
  /**
366
402
  * @see https://redis.io/commands/hscan
367
403
  */
@@ -470,6 +506,15 @@ class Pipeline {
470
506
  writable: true,
471
507
  value: (...args) => this.chain(new mod_js_1.LLenCommand(args, this.commandOptions))
472
508
  });
509
+ /**
510
+ * @see https://redis.io/commands/lmove
511
+ */
512
+ Object.defineProperty(this, "lmove", {
513
+ enumerable: true,
514
+ configurable: true,
515
+ writable: true,
516
+ value: (...args) => this.chain(new mod_js_1.LMoveCommand(args, this.commandOptions))
517
+ });
473
518
  /**
474
519
  * @see https://redis.io/commands/lpop
475
520
  */
@@ -839,6 +884,15 @@ class Pipeline {
839
884
  writable: true,
840
885
  value: (...args) => this.chain(new mod_js_1.SMembersCommand(args, this.commandOptions))
841
886
  });
887
+ /**
888
+ * @see https://redis.io/commands/smismember
889
+ */
890
+ Object.defineProperty(this, "smismember", {
891
+ enumerable: true,
892
+ configurable: true,
893
+ writable: true,
894
+ value: (key, members) => this.chain(new mod_js_1.SMIsMemberCommand([key, members], this.commandOptions))
895
+ });
842
896
  /**
843
897
  * @see https://redis.io/commands/smove
844
898
  */
@@ -1132,9 +1186,10 @@ class Pipeline {
1132
1186
  writable: true,
1133
1187
  value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
1134
1188
  });
1135
- this.client = client;
1189
+ this.client = opts.client;
1136
1190
  this.commands = [];
1137
- this.commandOptions = commandOptions;
1191
+ this.commandOptions = opts.commandOptions;
1192
+ this.multiExec = opts.multiExec ?? false;
1138
1193
  }
1139
1194
  /**
1140
1195
  * Pushes a command into the pipelien and returns a chainable instance of the
@@ -5,6 +5,7 @@ const mod_js_1 = require("./commands/mod.js");
5
5
  const pipeline_js_1 = require("./pipeline.js");
6
6
  const script_js_1 = require("./script.js");
7
7
  const zmscore_js_1 = require("./commands/zmscore.js");
8
+ const zdiffstore_js_1 = require("./commands/zdiffstore.js");
8
9
  /**
9
10
  * Serverless redis client for upstash.
10
11
  */
@@ -45,6 +46,24 @@ class Redis {
45
46
  this.client.request = (req) => middleware(req, makeRequest);
46
47
  }
47
48
  });
49
+ /**
50
+ * Technically this is not private, we can hide it from intellisense by doing this
51
+ */
52
+ Object.defineProperty(this, "addTelemetry", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: (telemetry) => {
57
+ try {
58
+ // @ts-ignore - The `Requester` interface does not know about this method but it will be there
59
+ // as long as the user uses the standard HttpClient
60
+ this.client.mergeTelemetry(telemetry);
61
+ }
62
+ catch {
63
+ // ignore
64
+ }
65
+ }
66
+ });
48
67
  /**
49
68
  * Create a new pipeline that allows you to send requests in bulk.
50
69
  *
@@ -54,7 +73,30 @@ class Redis {
54
73
  enumerable: true,
55
74
  configurable: true,
56
75
  writable: true,
57
- value: () => new pipeline_js_1.Pipeline(this.client, this.opts)
76
+ value: () => new pipeline_js_1.Pipeline({
77
+ client: this.client,
78
+ commandOptions: this.opts,
79
+ multiExec: false,
80
+ })
81
+ });
82
+ /**
83
+ * Create a new transaction to allow executing multiple steps atomically.
84
+ *
85
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
86
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
87
+ * guarantees that the commands are executed as a single isolated operation.
88
+ *
89
+ * @see {@link Pipeline}
90
+ */
91
+ Object.defineProperty(this, "multi", {
92
+ enumerable: true,
93
+ configurable: true,
94
+ writable: true,
95
+ value: () => new pipeline_js_1.Pipeline({
96
+ client: this.client,
97
+ commandOptions: this.opts,
98
+ multiExec: true,
99
+ })
58
100
  });
59
101
  /**
60
102
  * @see https://redis.io/commands/append
@@ -218,6 +260,15 @@ class Redis {
218
260
  writable: true,
219
261
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
220
262
  });
263
+ /**
264
+ * @see https://redis.io/commands/getdel
265
+ */
266
+ Object.defineProperty(this, "getdel", {
267
+ enumerable: true,
268
+ configurable: true,
269
+ writable: true,
270
+ value: (...args) => new mod_js_1.GetDelCommand(args, this.opts).exec(this.client)
271
+ });
221
272
  /**
222
273
  * @see https://redis.io/commands/getrange
223
274
  */
@@ -326,6 +377,16 @@ class Redis {
326
377
  writable: true,
327
378
  value: (key, kv) => new mod_js_1.HMSetCommand([key, kv], this.opts).exec(this.client)
328
379
  });
380
+ /**
381
+ * @see https://redis.io/commands/hrandfield
382
+ */
383
+ Object.defineProperty(this, "hrandfield", {
384
+ enumerable: true,
385
+ configurable: true,
386
+ writable: true,
387
+ value: (key, count, withValues) => new mod_js_1.HRandFieldCommand([key, count, withValues], this.opts)
388
+ .exec(this.client)
389
+ });
329
390
  /**
330
391
  * @see https://redis.io/commands/hscan
331
392
  */
@@ -434,6 +495,15 @@ class Redis {
434
495
  writable: true,
435
496
  value: (...args) => new mod_js_1.LLenCommand(args, this.opts).exec(this.client)
436
497
  });
498
+ /**
499
+ * @see https://redis.io/commands/lmove
500
+ */
501
+ Object.defineProperty(this, "lmove", {
502
+ enumerable: true,
503
+ configurable: true,
504
+ writable: true,
505
+ value: (...args) => new mod_js_1.LMoveCommand(args, this.opts).exec(this.client)
506
+ });
437
507
  /**
438
508
  * @see https://redis.io/commands/lpop
439
509
  */
@@ -794,6 +864,15 @@ class Redis {
794
864
  writable: true,
795
865
  value: (key, member) => new mod_js_1.SIsMemberCommand([key, member], this.opts).exec(this.client)
796
866
  });
867
+ /**
868
+ * @see https://redis.io/commands/smismember
869
+ */
870
+ Object.defineProperty(this, "smismember", {
871
+ enumerable: true,
872
+ configurable: true,
873
+ writable: true,
874
+ value: (key, members) => new mod_js_1.SMIsMemberCommand([key, members], this.opts).exec(this.client)
875
+ });
797
876
  /**
798
877
  * @see https://redis.io/commands/smembers
799
878
  */
@@ -952,6 +1031,15 @@ class Redis {
952
1031
  writable: true,
953
1032
  value: (...args) => new mod_js_1.ZCountCommand(args, this.opts).exec(this.client)
954
1033
  });
1034
+ /**
1035
+ * @see https://redis.io/commands/zdiffstore
1036
+ */
1037
+ Object.defineProperty(this, "zdiffstore", {
1038
+ enumerable: true,
1039
+ configurable: true,
1040
+ writable: true,
1041
+ value: (...args) => new zdiffstore_js_1.ZDiffStoreCommand(args, this.opts).exec(this.client)
1042
+ });
955
1043
  /**
956
1044
  * @see https://redis.io/commands/zincrby
957
1045
  */