@upstash/redis 0.0.0-ci.817cf518-20220823 → 0.0.0-ci.8500f14d-20221123

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/README.md CHANGED
@@ -81,24 +81,6 @@ data = await redis.spop('animals', 1)
81
81
  console.log(data)
82
82
  ```
83
83
 
84
- ### Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
85
-
86
- If you are running on nodejs v17 and earlier, `fetch` will not be natively
87
- supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
88
- for you. But if you are running on bare node, you need to either specify a
89
- polyfill yourself or change the import path to:
90
-
91
- ```typescript
92
- import { Redis } from "@upstash/redis/with-fetch";
93
- ```
94
-
95
- ### Upgrading from v0.2.0?
96
-
97
- Please read the
98
- [migration guide](https://docs.upstash.com/redis/sdks/javascriptsdk/migration).
99
- For further explanation we wrote a
100
- [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
101
-
102
84
  ## Docs
103
85
 
104
86
  See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
@@ -119,5 +101,18 @@ the url and token
119
101
  UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
120
102
  ```
121
103
 
122
- ```
104
+ ### Telemetry
105
+
106
+ This library sends anonymous telemetry data to help us improve your experience.
107
+ We collect the following:
108
+
109
+ - SDK version
110
+ - Platform (Deno, Cloudflare, Vercel)
111
+ - Runtime version (node@18.x)
112
+
113
+ You can opt out by setting the `UPSTASH_DISABLE_TELEMETRY` environment variable
114
+ to any truthy value.
115
+
116
+ ```sh
117
+ UPSTASH_DISABLE_TELEMETRY=1
123
118
  ```
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getdel
4
+ */
5
+ export class GetDelCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["getdel", ...cmd], opts);
8
+ }
9
+ }
@@ -19,6 +19,7 @@ export * from "./get.js";
19
19
  export * from "./getbit.js";
20
20
  export * from "./getrange.js";
21
21
  export * from "./getset.js";
22
+ export * from "./getdel.js";
22
23
  export * from "./hdel.js";
23
24
  export * from "./hexists.js";
24
25
  export * from "./hget.js";
@@ -0,0 +1,10 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/zmscore
4
+ */
5
+ export class ZMScoreCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ const [key, members] = cmd;
8
+ super(["zmscore", key, ...members], opts);
9
+ }
10
+ }
package/esm/pkg/http.js CHANGED
@@ -25,9 +25,28 @@ export class HttpClient {
25
25
  writable: true,
26
26
  value: void 0
27
27
  });
28
+ this.options = {
29
+ backend: config.options?.backend,
30
+ agent: config.agent,
31
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
32
+ };
28
33
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
29
- this.headers = { "Content-Type": "application/json", ...config.headers };
30
- this.options = { backend: config.options?.backend };
34
+ this.headers = {
35
+ "Content-Type": "application/json",
36
+ ...config.headers,
37
+ };
38
+ if (config.telemetry?.runtime) {
39
+ this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
40
+ }
41
+ if (config.telemetry?.platform) {
42
+ this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
43
+ }
44
+ if (config.telemetry?.sdk) {
45
+ this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
46
+ }
47
+ if (this.options.responseEncoding === "base64") {
48
+ this.headers["Upstash-Encoding"] = "base64";
49
+ }
31
50
  if (typeof config?.retry === "boolean" && config?.retry === false) {
32
51
  this.retry = {
33
52
  attempts: 1,
@@ -48,6 +67,7 @@ export class HttpClient {
48
67
  headers: this.headers,
49
68
  body: JSON.stringify(req.body),
50
69
  keepalive: true,
70
+ agent: this.options?.agent,
51
71
  /**
52
72
  * Fastly specific
53
73
  */
@@ -72,6 +92,66 @@ export class HttpClient {
72
92
  if (!res.ok) {
73
93
  throw new UpstashError(body.error);
74
94
  }
95
+ if (this.options?.responseEncoding === "base64") {
96
+ return Array.isArray(body) ? body.map(decode) : decode(body);
97
+ }
75
98
  return body;
76
99
  }
77
100
  }
101
+ function base64decode(b64) {
102
+ let dec = "";
103
+ try {
104
+ /**
105
+ * Using only atob() is not enough because it doesn't work with unicode characters
106
+ */
107
+ const binString = atob(b64);
108
+ const size = binString.length;
109
+ const bytes = new Uint8Array(size);
110
+ for (let i = 0; i < size; i++) {
111
+ bytes[i] = binString.charCodeAt(i);
112
+ }
113
+ dec = new TextDecoder().decode(bytes);
114
+ }
115
+ catch {
116
+ dec = b64;
117
+ }
118
+ try {
119
+ return decodeURIComponent(dec);
120
+ }
121
+ catch {
122
+ return dec;
123
+ }
124
+ }
125
+ function decode(raw) {
126
+ let result = undefined;
127
+ switch (typeof raw.result) {
128
+ case "undefined":
129
+ return raw;
130
+ case "number": {
131
+ result = raw.result;
132
+ break;
133
+ }
134
+ case "object": {
135
+ if (Array.isArray(raw.result)) {
136
+ result = raw.result.map((v) => typeof v === "string"
137
+ ? base64decode(v)
138
+ : Array.isArray(v)
139
+ ? v.map(base64decode)
140
+ : v);
141
+ }
142
+ else {
143
+ // If it's not an array it must be null
144
+ // Apparently null is an object in javascript
145
+ result = null;
146
+ }
147
+ break;
148
+ }
149
+ case "string": {
150
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
151
+ break;
152
+ }
153
+ default:
154
+ break;
155
+ }
156
+ return { result, error: raw.error };
157
+ }
@@ -1,5 +1,6 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { UpstashError } from "./error.js";
3
+ import { ZMScoreCommand } from "./commands/zmscore.js";
3
4
  /**
4
5
  * Upstash REST API supports command pipelining to send multiple commands in
5
6
  * batch, instead of sending each command one by one and waiting for a response.
@@ -16,7 +17,7 @@ import { UpstashError } from "./error.js";
16
17
  * **Examples:**
17
18
  *
18
19
  * ```ts
19
- * const p = redis.pipeline()
20
+ * const p = redis.pipeline() // or redis.multi()
20
21
  * p.set("key","value")
21
22
  * p.get("key")
22
23
  * const res = await p.exec()
@@ -39,7 +40,7 @@ import { UpstashError } from "./error.js";
39
40
  * ```
40
41
  */
41
42
  export class Pipeline {
42
- constructor(client, commandOptions) {
43
+ constructor(opts) {
43
44
  Object.defineProperty(this, "client", {
44
45
  enumerable: true,
45
46
  configurable: true,
@@ -58,6 +59,12 @@ export class Pipeline {
58
59
  writable: true,
59
60
  value: void 0
60
61
  });
62
+ Object.defineProperty(this, "multiExec", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
61
68
  /**
62
69
  * Send the pipeline request to upstash.
63
70
  *
@@ -76,8 +83,9 @@ export class Pipeline {
76
83
  if (this.commands.length === 0) {
77
84
  throw new Error("Pipeline is empty");
78
85
  }
86
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
79
87
  const res = (await this.client.request({
80
- path: ["pipeline"],
88
+ path,
81
89
  body: Object.values(this.commands).map((c) => c.command),
82
90
  }));
83
91
  return res.map(({ error, result }, i) => {
@@ -250,6 +258,15 @@ export class Pipeline {
250
258
  writable: true,
251
259
  value: (...args) => this.chain(new GetBitCommand(args, this.commandOptions))
252
260
  });
261
+ /**
262
+ * @see https://redis.io/commands/getdel
263
+ */
264
+ Object.defineProperty(this, "getdel", {
265
+ enumerable: true,
266
+ configurable: true,
267
+ writable: true,
268
+ value: (...args) => this.chain(new GetDelCommand(args, this.commandOptions))
269
+ });
253
270
  /**
254
271
  * @see https://redis.io/commands/getrange
255
272
  */
@@ -1011,6 +1028,15 @@ export class Pipeline {
1011
1028
  writable: true,
1012
1029
  value: (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions))
1013
1030
  });
1031
+ /**
1032
+ * @see https://redis.io/commands/zmscore
1033
+ */
1034
+ Object.defineProperty(this, "zmscore", {
1035
+ enumerable: true,
1036
+ configurable: true,
1037
+ writable: true,
1038
+ value: (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions))
1039
+ });
1014
1040
  /**
1015
1041
  * @see https://redis.io/commands/zpopmax
1016
1042
  */
@@ -1119,9 +1145,10 @@ export class Pipeline {
1119
1145
  writable: true,
1120
1146
  value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
1121
1147
  });
1122
- this.client = client;
1148
+ this.client = opts.client;
1123
1149
  this.commands = [];
1124
- this.commandOptions = commandOptions;
1150
+ this.commandOptions = opts.commandOptions;
1151
+ this.multiExec = opts.multiExec ?? false;
1125
1152
  }
1126
1153
  /**
1127
1154
  * Pushes a command into the pipelien and returns a chainable instance of the
package/esm/pkg/redis.js CHANGED
@@ -1,6 +1,7 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { Pipeline } from "./pipeline.js";
3
3
  import { Script } from "./script.js";
4
+ import { ZMScoreCommand } from "./commands/zmscore.js";
4
5
  /**
5
6
  * Serverless redis client for upstash.
6
7
  */
@@ -50,7 +51,30 @@ export class Redis {
50
51
  enumerable: true,
51
52
  configurable: true,
52
53
  writable: true,
53
- value: () => new Pipeline(this.client, this.opts)
54
+ value: () => new Pipeline({
55
+ client: this.client,
56
+ commandOptions: this.opts,
57
+ multiExec: false,
58
+ })
59
+ });
60
+ /**
61
+ * Create a new transaction to allow executing multiple steps atomically.
62
+ *
63
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
64
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
65
+ * guarantees that the commands are executed as a single isolated operation.
66
+ *
67
+ * @see {@link Pipeline}
68
+ */
69
+ Object.defineProperty(this, "multi", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: () => new Pipeline({
74
+ client: this.client,
75
+ commandOptions: this.opts,
76
+ multiExec: true,
77
+ })
54
78
  });
55
79
  /**
56
80
  * @see https://redis.io/commands/append
@@ -214,6 +238,15 @@ export class Redis {
214
238
  writable: true,
215
239
  value: (...args) => new GetBitCommand(args, this.opts).exec(this.client)
216
240
  });
241
+ /**
242
+ * @see https://redis.io/commands/getdel
243
+ */
244
+ Object.defineProperty(this, "getdel", {
245
+ enumerable: true,
246
+ configurable: true,
247
+ writable: true,
248
+ value: (...args) => new GetDelCommand(args, this.opts).exec(this.client)
249
+ });
217
250
  /**
218
251
  * @see https://redis.io/commands/getrange
219
252
  */
@@ -975,6 +1008,15 @@ export class Redis {
975
1008
  writable: true,
976
1009
  value: (...args) => new ZLexCountCommand(args, this.opts).exec(this.client)
977
1010
  });
1011
+ /**
1012
+ * @see https://redis.io/commands/zmscore
1013
+ */
1014
+ Object.defineProperty(this, "zmscore", {
1015
+ enumerable: true,
1016
+ configurable: true,
1017
+ writable: true,
1018
+ value: (...args) => new ZMScoreCommand(args, this.opts).exec(this.client)
1019
+ });
978
1020
  /**
979
1021
  * @see https://redis.io/commands/zpopmax
980
1022
  */
@@ -1,5 +1,6 @@
1
1
  import * as core from "../pkg/redis.js";
2
2
  import { HttpClient } from "../pkg/http.js";
3
+ import { VERSION } from "../version.js";
3
4
  /**
4
5
  * Serverless redis client for upstash.
5
6
  */
@@ -15,7 +16,7 @@ export class Redis extends core.Redis {
15
16
  * });
16
17
  * ```
17
18
  */
18
- constructor(config) {
19
+ constructor(config, env) {
19
20
  if (config.url.startsWith(" ") ||
20
21
  config.url.endsWith(" ") ||
21
22
  /\r|\n/.test(config.url)) {
@@ -26,10 +27,17 @@ export class Redis extends core.Redis {
26
27
  /\r|\n/.test(config.token)) {
27
28
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
28
29
  }
30
+ const telemetry = {};
31
+ if (!env?.UPSTASH_DISABLE_TELEMETRY) {
32
+ telemetry.platform = "cloudflare";
33
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
34
+ }
29
35
  const client = new HttpClient({
30
36
  retry: config.retry,
31
37
  baseUrl: config.url,
32
38
  headers: { authorization: `Bearer ${config.token}` },
39
+ responseEncoding: config.responseEncoding,
40
+ telemetry,
33
41
  });
34
42
  super(client, {
35
43
  automaticDeserialization: config.automaticDeserialization,
@@ -57,6 +65,6 @@ export class Redis extends core.Redis {
57
65
  if (!token) {
58
66
  throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
59
67
  }
60
- return new Redis({ ...opts, url, token });
68
+ return new Redis({ ...opts, url, token }, env);
61
69
  }
62
70
  }
@@ -32,6 +32,7 @@ export class Redis extends core.Redis {
32
32
  retry: config.retry,
33
33
  headers: { authorization: `Bearer ${config.token}` },
34
34
  options: { backend: config.backend },
35
+ responseEncoding: config.responseEncoding,
35
36
  });
36
37
  super(client, {
37
38
  automaticDeserialization: config.automaticDeserialization,
@@ -1,6 +1,7 @@
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";
5
6
  /**
6
7
  * Serverless redis client for upstash.
@@ -21,11 +22,23 @@ export class Redis extends core.Redis {
21
22
  /\r|\n/.test(configOrRequester.token)) {
22
23
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
23
24
  }
25
+ const telemetry = {};
26
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
27
+ telemetry.runtime = `node@${process.version}`;
28
+ telemetry.platform = process.env.VERCEL
29
+ ? "vercel"
30
+ : process.env.AWS_REGION
31
+ ? "aws"
32
+ : "unknown";
33
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
34
+ }
24
35
  const client = new HttpClient({
25
36
  baseUrl: configOrRequester.url,
26
37
  retry: configOrRequester.retry,
27
38
  headers: { authorization: `Bearer ${configOrRequester.token}` },
28
- // agent: configOrRequester.agent,
39
+ // agent: configOrRequester.agent,
40
+ responseEncoding: configOrRequester.responseEncoding,
41
+ telemetry,
29
42
  });
30
43
  super(client, {
31
44
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -1,6 +1,7 @@
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
  /**
5
6
  * Serverless redis client for upstash.
6
7
  */
@@ -20,11 +21,23 @@ export class Redis extends core.Redis {
20
21
  /\r|\n/.test(configOrRequester.token)) {
21
22
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
22
23
  }
24
+ const telemetry = {};
25
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
26
+ telemetry.runtime = `node@${process.version}`;
27
+ telemetry.platform = process.env.VERCEL
28
+ ? "vercel"
29
+ : process.env.AWS_REGION
30
+ ? "aws"
31
+ : "unknown";
32
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
33
+ }
23
34
  const client = new HttpClient({
24
35
  baseUrl: configOrRequester.url,
25
36
  retry: configOrRequester.retry,
26
37
  headers: { authorization: `Bearer ${configOrRequester.token}` },
27
- // agent: configOrRequester.agent,
38
+ agent: configOrRequester.agent,
39
+ responseEncoding: configOrRequester.responseEncoding,
40
+ telemetry,
28
41
  });
29
42
  super(client, {
30
43
  automaticDeserialization: configOrRequester.automaticDeserialization,
package/esm/version.js ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = "v0.0.0-ci.8500f14d-20221123";
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.817cf518-20220823",
6
+ "version": "v0.0.0-ci.8500f14d-20221123",
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;
@@ -35,6 +35,7 @@ __exportStar(require("./get.js"), exports);
35
35
  __exportStar(require("./getbit.js"), exports);
36
36
  __exportStar(require("./getrange.js"), exports);
37
37
  __exportStar(require("./getset.js"), exports);
38
+ __exportStar(require("./getdel.js"), exports);
38
39
  __exportStar(require("./hdel.js"), exports);
39
40
  __exportStar(require("./hexists.js"), exports);
40
41
  __exportStar(require("./hget.js"), exports);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZMScoreCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/zmscore
7
+ */
8
+ class ZMScoreCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ const [key, members] = cmd;
11
+ super(["zmscore", key, ...members], opts);
12
+ }
13
+ }
14
+ exports.ZMScoreCommand = ZMScoreCommand;
@@ -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,
@@ -51,6 +70,7 @@ class HttpClient {
51
70
  headers: this.headers,
52
71
  body: JSON.stringify(req.body),
53
72
  keepalive: true,
73
+ agent: this.options?.agent,
54
74
  /**
55
75
  * Fastly specific
56
76
  */
@@ -75,7 +95,67 @@ class HttpClient {
75
95
  if (!res.ok) {
76
96
  throw new error_js_1.UpstashError(body.error);
77
97
  }
98
+ if (this.options?.responseEncoding === "base64") {
99
+ return Array.isArray(body) ? body.map(decode) : decode(body);
100
+ }
78
101
  return body;
79
102
  }
80
103
  }
81
104
  exports.HttpClient = HttpClient;
105
+ function base64decode(b64) {
106
+ let dec = "";
107
+ try {
108
+ /**
109
+ * Using only atob() is not enough because it doesn't work with unicode characters
110
+ */
111
+ const binString = atob(b64);
112
+ const size = binString.length;
113
+ const bytes = new Uint8Array(size);
114
+ for (let i = 0; i < size; i++) {
115
+ bytes[i] = binString.charCodeAt(i);
116
+ }
117
+ dec = new TextDecoder().decode(bytes);
118
+ }
119
+ catch {
120
+ dec = b64;
121
+ }
122
+ try {
123
+ return decodeURIComponent(dec);
124
+ }
125
+ catch {
126
+ return dec;
127
+ }
128
+ }
129
+ function decode(raw) {
130
+ let result = undefined;
131
+ switch (typeof raw.result) {
132
+ case "undefined":
133
+ return raw;
134
+ case "number": {
135
+ result = raw.result;
136
+ break;
137
+ }
138
+ case "object": {
139
+ if (Array.isArray(raw.result)) {
140
+ result = raw.result.map((v) => typeof v === "string"
141
+ ? base64decode(v)
142
+ : Array.isArray(v)
143
+ ? v.map(base64decode)
144
+ : v);
145
+ }
146
+ else {
147
+ // If it's not an array it must be null
148
+ // Apparently null is an object in javascript
149
+ result = null;
150
+ }
151
+ break;
152
+ }
153
+ case "string": {
154
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
155
+ break;
156
+ }
157
+ default:
158
+ break;
159
+ }
160
+ return { result, error: raw.error };
161
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Pipeline = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const error_js_1 = require("./error.js");
6
+ const zmscore_js_1 = require("./commands/zmscore.js");
6
7
  /**
7
8
  * Upstash REST API supports command pipelining to send multiple commands in
8
9
  * batch, instead of sending each command one by one and waiting for a response.
@@ -19,7 +20,7 @@ const error_js_1 = require("./error.js");
19
20
  * **Examples:**
20
21
  *
21
22
  * ```ts
22
- * const p = redis.pipeline()
23
+ * const p = redis.pipeline() // or redis.multi()
23
24
  * p.set("key","value")
24
25
  * p.get("key")
25
26
  * const res = await p.exec()
@@ -42,7 +43,7 @@ const error_js_1 = require("./error.js");
42
43
  * ```
43
44
  */
44
45
  class Pipeline {
45
- constructor(client, commandOptions) {
46
+ constructor(opts) {
46
47
  Object.defineProperty(this, "client", {
47
48
  enumerable: true,
48
49
  configurable: true,
@@ -61,6 +62,12 @@ class Pipeline {
61
62
  writable: true,
62
63
  value: void 0
63
64
  });
65
+ Object.defineProperty(this, "multiExec", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
64
71
  /**
65
72
  * Send the pipeline request to upstash.
66
73
  *
@@ -79,8 +86,9 @@ class Pipeline {
79
86
  if (this.commands.length === 0) {
80
87
  throw new Error("Pipeline is empty");
81
88
  }
89
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
82
90
  const res = (await this.client.request({
83
- path: ["pipeline"],
91
+ path,
84
92
  body: Object.values(this.commands).map((c) => c.command),
85
93
  }));
86
94
  return res.map(({ error, result }, i) => {
@@ -253,6 +261,15 @@ class Pipeline {
253
261
  writable: true,
254
262
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
255
263
  });
264
+ /**
265
+ * @see https://redis.io/commands/getdel
266
+ */
267
+ Object.defineProperty(this, "getdel", {
268
+ enumerable: true,
269
+ configurable: true,
270
+ writable: true,
271
+ value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
272
+ });
256
273
  /**
257
274
  * @see https://redis.io/commands/getrange
258
275
  */
@@ -1014,6 +1031,15 @@ class Pipeline {
1014
1031
  writable: true,
1015
1032
  value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
1016
1033
  });
1034
+ /**
1035
+ * @see https://redis.io/commands/zmscore
1036
+ */
1037
+ Object.defineProperty(this, "zmscore", {
1038
+ enumerable: true,
1039
+ configurable: true,
1040
+ writable: true,
1041
+ value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
1042
+ });
1017
1043
  /**
1018
1044
  * @see https://redis.io/commands/zpopmax
1019
1045
  */
@@ -1122,9 +1148,10 @@ class Pipeline {
1122
1148
  writable: true,
1123
1149
  value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
1124
1150
  });
1125
- this.client = client;
1151
+ this.client = opts.client;
1126
1152
  this.commands = [];
1127
- this.commandOptions = commandOptions;
1153
+ this.commandOptions = opts.commandOptions;
1154
+ this.multiExec = opts.multiExec ?? false;
1128
1155
  }
1129
1156
  /**
1130
1157
  * Pushes a command into the pipelien and returns a chainable instance of the
@@ -4,6 +4,7 @@ exports.Redis = void 0;
4
4
  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
+ const zmscore_js_1 = require("./commands/zmscore.js");
7
8
  /**
8
9
  * Serverless redis client for upstash.
9
10
  */
@@ -53,7 +54,30 @@ class Redis {
53
54
  enumerable: true,
54
55
  configurable: true,
55
56
  writable: true,
56
- value: () => new pipeline_js_1.Pipeline(this.client, this.opts)
57
+ value: () => new pipeline_js_1.Pipeline({
58
+ client: this.client,
59
+ commandOptions: this.opts,
60
+ multiExec: false,
61
+ })
62
+ });
63
+ /**
64
+ * Create a new transaction to allow executing multiple steps atomically.
65
+ *
66
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
67
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
68
+ * guarantees that the commands are executed as a single isolated operation.
69
+ *
70
+ * @see {@link Pipeline}
71
+ */
72
+ Object.defineProperty(this, "multi", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: () => new pipeline_js_1.Pipeline({
77
+ client: this.client,
78
+ commandOptions: this.opts,
79
+ multiExec: true,
80
+ })
57
81
  });
58
82
  /**
59
83
  * @see https://redis.io/commands/append
@@ -217,6 +241,15 @@ class Redis {
217
241
  writable: true,
218
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
219
243
  });
244
+ /**
245
+ * @see https://redis.io/commands/getdel
246
+ */
247
+ Object.defineProperty(this, "getdel", {
248
+ enumerable: true,
249
+ configurable: true,
250
+ writable: true,
251
+ value: (...args) => new mod_js_1.GetDelCommand(args, this.opts).exec(this.client)
252
+ });
220
253
  /**
221
254
  * @see https://redis.io/commands/getrange
222
255
  */
@@ -978,6 +1011,15 @@ class Redis {
978
1011
  writable: true,
979
1012
  value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
980
1013
  });
1014
+ /**
1015
+ * @see https://redis.io/commands/zmscore
1016
+ */
1017
+ Object.defineProperty(this, "zmscore", {
1018
+ enumerable: true,
1019
+ configurable: true,
1020
+ writable: true,
1021
+ value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
1022
+ });
981
1023
  /**
982
1024
  * @see https://redis.io/commands/zpopmax
983
1025
  */
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Redis = void 0;
27
27
  const core = __importStar(require("../pkg/redis.js"));
28
28
  const http_js_1 = require("../pkg/http.js");
29
+ const version_js_1 = require("../version.js");
29
30
  /**
30
31
  * Serverless redis client for upstash.
31
32
  */
@@ -41,7 +42,7 @@ class Redis extends core.Redis {
41
42
  * });
42
43
  * ```
43
44
  */
44
- constructor(config) {
45
+ constructor(config, env) {
45
46
  if (config.url.startsWith(" ") ||
46
47
  config.url.endsWith(" ") ||
47
48
  /\r|\n/.test(config.url)) {
@@ -52,10 +53,17 @@ class Redis extends core.Redis {
52
53
  /\r|\n/.test(config.token)) {
53
54
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
54
55
  }
56
+ const telemetry = {};
57
+ if (!env?.UPSTASH_DISABLE_TELEMETRY) {
58
+ telemetry.platform = "cloudflare";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
55
61
  const client = new http_js_1.HttpClient({
56
62
  retry: config.retry,
57
63
  baseUrl: config.url,
58
64
  headers: { authorization: `Bearer ${config.token}` },
65
+ responseEncoding: config.responseEncoding,
66
+ telemetry,
59
67
  });
60
68
  super(client, {
61
69
  automaticDeserialization: config.automaticDeserialization,
@@ -83,7 +91,7 @@ class Redis extends core.Redis {
83
91
  if (!token) {
84
92
  throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
85
93
  }
86
- return new Redis({ ...opts, url, token });
94
+ return new Redis({ ...opts, url, token }, env);
87
95
  }
88
96
  }
89
97
  exports.Redis = Redis;
@@ -58,6 +58,7 @@ class Redis extends core.Redis {
58
58
  retry: config.retry,
59
59
  headers: { authorization: `Bearer ${config.token}` },
60
60
  options: { backend: config.backend },
61
+ responseEncoding: config.responseEncoding,
61
62
  });
62
63
  super(client, {
63
64
  automaticDeserialization: config.automaticDeserialization,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  require("isomorphic-fetch");
31
32
  /**
32
33
  * Serverless redis client for upstash.
@@ -47,11 +48,23 @@ class Redis extends core.Redis {
47
48
  /\r|\n/.test(configOrRequester.token)) {
48
49
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
49
50
  }
51
+ const telemetry = {};
52
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
53
+ telemetry.runtime = `node@${process.version}`;
54
+ telemetry.platform = process.env.VERCEL
55
+ ? "vercel"
56
+ : process.env.AWS_REGION
57
+ ? "aws"
58
+ : "unknown";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
50
61
  const client = new http_js_1.HttpClient({
51
62
  baseUrl: configOrRequester.url,
52
63
  retry: configOrRequester.retry,
53
64
  headers: { authorization: `Bearer ${configOrRequester.token}` },
54
- // agent: configOrRequester.agent,
65
+ // agent: configOrRequester.agent,
66
+ responseEncoding: configOrRequester.responseEncoding,
67
+ telemetry,
55
68
  });
56
69
  super(client, {
57
70
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  /**
31
32
  * Serverless redis client for upstash.
32
33
  */
@@ -46,11 +47,23 @@ class Redis extends core.Redis {
46
47
  /\r|\n/.test(configOrRequester.token)) {
47
48
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
48
49
  }
50
+ const telemetry = {};
51
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
52
+ telemetry.runtime = `node@${process.version}`;
53
+ telemetry.platform = process.env.VERCEL
54
+ ? "vercel"
55
+ : process.env.AWS_REGION
56
+ ? "aws"
57
+ : "unknown";
58
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
59
+ }
49
60
  const client = new http_js_1.HttpClient({
50
61
  baseUrl: configOrRequester.url,
51
62
  retry: configOrRequester.retry,
52
63
  headers: { authorization: `Bearer ${configOrRequester.token}` },
53
- // agent: configOrRequester.agent,
64
+ agent: configOrRequester.agent,
65
+ responseEncoding: configOrRequester.responseEncoding,
66
+ telemetry,
54
67
  });
55
68
  super(client, {
56
69
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = "v0.0.0-ci.8500f14d-20221123";
@@ -0,0 +1,7 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getdel
4
+ */
5
+ export declare class GetDelCommand<TData = string> extends Command<unknown | null, TData | null> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
7
+ }
@@ -19,6 +19,7 @@ export * from "./get.js";
19
19
  export * from "./getbit.js";
20
20
  export * from "./getrange.js";
21
21
  export * from "./getset.js";
22
+ export * from "./getdel.js";
22
23
  export * from "./hdel.js";
23
24
  export * from "./hexists.js";
24
25
  export * from "./hget.js";
@@ -0,0 +1,7 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/zmscore
4
+ */
5
+ export declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] | null> {
6
+ constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
7
+ }
@@ -29,20 +29,69 @@ export declare type RetryConfig = false | {
29
29
  */
30
30
  backoff?: (retryCount: number) => number;
31
31
  };
32
- declare type Options = {
32
+ export declare type Options = {
33
33
  backend?: string;
34
34
  };
35
+ export declare type RequesterConfig = {
36
+ /**
37
+ * Configure the retry behaviour in case of network errors
38
+ */
39
+ retry?: RetryConfig;
40
+ /**
41
+ * Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
42
+ * valid json and will therefore cause errors when deserializing. This used to happen very
43
+ * frequently with non-utf8 data, such as emojis.
44
+ *
45
+ * By default we will therefore encode the data as base64 on the server, before sending it to the
46
+ * client. The client will then decode the base64 data and parse it as utf8.
47
+ *
48
+ * For very large entries, this can add a few milliseconds, so if you are sure that your data is
49
+ * valid utf8, you can disable this behaviour by setting this option to false.
50
+ *
51
+ * Here's what the response body looks like:
52
+ *
53
+ * ```json
54
+ * {
55
+ * result?: "base64-encoded",
56
+ * error?: string
57
+ * }
58
+ * ```
59
+ *
60
+ * @default "base64"
61
+ */
62
+ responseEncoding?: false | "base64";
63
+ };
35
64
  export declare type HttpClientConfig = {
36
65
  headers?: Record<string, string>;
37
66
  baseUrl: string;
38
67
  options?: Options;
39
68
  retry?: RetryConfig;
40
- };
69
+ agent?: any;
70
+ telemetry?: {
71
+ /**
72
+ * Upstash-Telemetry-Sdk
73
+ * @example @upstash/redis@v1.1.1
74
+ */
75
+ sdk?: string;
76
+ /**
77
+ * Upstash-Telemetry-Platform
78
+ * @example cloudflare
79
+ */
80
+ platform?: string;
81
+ /**
82
+ * Upstash-Telemetry-Runtime
83
+ * @example node@v18
84
+ */
85
+ runtime?: string;
86
+ };
87
+ } & RequesterConfig;
41
88
  export declare class HttpClient implements Requester {
42
89
  baseUrl: string;
43
90
  headers: Record<string, string>;
44
- readonly options?: {
91
+ readonly options: {
45
92
  backend?: string;
93
+ agent: any;
94
+ responseEncoding?: false | "base64";
46
95
  };
47
96
  readonly retry: {
48
97
  attempts: number;
@@ -51,4 +100,3 @@ export declare class HttpClient implements Requester {
51
100
  constructor(config: HttpClientConfig);
52
101
  request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
53
102
  }
54
- export {};
@@ -18,7 +18,7 @@ import { CommandArgs } from "./types.js";
18
18
  * **Examples:**
19
19
  *
20
20
  * ```ts
21
- * const p = redis.pipeline()
21
+ * const p = redis.pipeline() // or redis.multi()
22
22
  * p.set("key","value")
23
23
  * p.get("key")
24
24
  * const res = await p.exec()
@@ -44,7 +44,12 @@ export declare class Pipeline {
44
44
  private client;
45
45
  private commands;
46
46
  private commandOptions?;
47
- constructor(client: Requester, commandOptions?: CommandOptions<any, any>);
47
+ private multiExec;
48
+ constructor(opts: {
49
+ client: Requester;
50
+ commandOptions?: CommandOptions<any, any>;
51
+ multiExec?: boolean;
52
+ });
48
53
  /**
49
54
  * Send the pipeline request to upstash.
50
55
  *
@@ -138,6 +143,10 @@ export declare class Pipeline {
138
143
  * @see https://redis.io/commands/getbit
139
144
  */
140
145
  getbit: (key: string, offset: number) => this;
146
+ /**
147
+ * @see https://redis.io/commands/getdel
148
+ */
149
+ getdel: <TData>(key: string) => this;
141
150
  /**
142
151
  * @see https://redis.io/commands/getrange
143
152
  */
@@ -483,6 +492,10 @@ export declare class Pipeline {
483
492
  * @see https://redis.io/commands/zlexcount
484
493
  */
485
494
  zlexcount: (key: string, min: string, max: string) => this;
495
+ /**
496
+ * @see https://redis.io/commands/zmscore
497
+ */
498
+ zmscore: (key: string, members: unknown[]) => this;
486
499
  /**
487
500
  * @see https://redis.io/commands/zpopmax
488
501
  */
@@ -40,6 +40,16 @@ export declare class Redis {
40
40
  * @see {@link Pipeline}
41
41
  */
42
42
  pipeline: () => Pipeline;
43
+ /**
44
+ * Create a new transaction to allow executing multiple steps atomically.
45
+ *
46
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
47
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
48
+ * guarantees that the commands are executed as a single isolated operation.
49
+ *
50
+ * @see {@link Pipeline}
51
+ */
52
+ multi: () => Pipeline;
43
53
  /**
44
54
  * @see https://redis.io/commands/append
45
55
  */
@@ -117,6 +127,10 @@ export declare class Redis {
117
127
  * @see https://redis.io/commands/getbit
118
128
  */
119
129
  getbit: (key: string, offset: number) => Promise<0 | 1>;
130
+ /**
131
+ * @see https://redis.io/commands/getdel
132
+ */
133
+ getdel: <TData>(key: string) => Promise<TData | null>;
120
134
  /**
121
135
  * @see https://redis.io/commands/getrange
122
136
  */
@@ -465,6 +479,10 @@ export declare class Redis {
465
479
  * @see https://redis.io/commands/zlexcount
466
480
  */
467
481
  zlexcount: (key: string, min: string, max: string) => Promise<number>;
482
+ /**
483
+ * @see https://redis.io/commands/zmscore
484
+ */
485
+ zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
468
486
  /**
469
487
  * @see https://redis.io/commands/zpopmax
470
488
  */
@@ -1,5 +1,9 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
+ import { RequesterConfig } from "../pkg/http.js";
4
+ declare type Env = {
5
+ UPSTASH_DISABLE_TELEMETRY?: string;
6
+ };
3
7
  export type { Requester, UpstashRequest, UpstashResponse };
4
8
  /**
5
9
  * Connection credentials for upstash redis.
@@ -14,11 +18,7 @@ export declare type RedisConfigCloudflare = {
14
18
  * UPSTASH_REDIS_REST_TOKEN
15
19
  */
16
20
  token: string;
17
- /**
18
- * Configure the retry behaviour in case of network errors
19
- */
20
- retry?: RetryConfig;
21
- } & core.RedisOptions;
21
+ } & core.RedisOptions & RequesterConfig & Env;
22
22
  /**
23
23
  * Serverless redis client for upstash.
24
24
  */
@@ -34,9 +34,10 @@ export declare class Redis extends core.Redis {
34
34
  * });
35
35
  * ```
36
36
  */
37
- constructor(config: RedisConfigCloudflare);
37
+ constructor(config: RedisConfigCloudflare, env?: Env);
38
38
  static fromEnv(env?: {
39
39
  UPSTASH_REDIS_REST_URL: string;
40
40
  UPSTASH_REDIS_REST_TOKEN: string;
41
+ UPSTASH_DISABLE_TELEMETRY?: string;
41
42
  }, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
42
43
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -20,11 +20,7 @@ export declare type RedisConfigFastly = {
20
20
  * referenced by name.
21
21
  */
22
22
  backend: string;
23
- /**
24
- * Configure the retry behaviour in case of network errors
25
- */
26
- retry?: RetryConfig;
27
- } & core.RedisOptions;
23
+ } & core.RedisOptions & RequesterConfig;
28
24
  /**
29
25
  * Serverless redis client for upstash.
30
26
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  import "isomorphic-fetch";
4
4
  export type { Requester, UpstashRequest, UpstashResponse };
5
5
  /**
@@ -15,26 +15,7 @@ export declare type RedisConfigNodejs = {
15
15
  * UPSTASH_REDIS_REST_TOKEN
16
16
  */
17
17
  token: string;
18
- /**
19
- * An agent allows you to reuse connections to reduce latency for multiple sequential requests.
20
- *
21
- * This is a node specific implementation and is not supported in various runtimes like Vercel
22
- * edge functions.
23
- *
24
- * @example
25
- * ```ts
26
- * import https from "https"
27
- *
28
- * const options: RedisConfigNodejs = {
29
- * agent: new https.Agent({ keepAlive: true })
30
- * }
31
- * ```
32
- */
33
- /**
34
- * Configure the retry behaviour in case of network errors
35
- */
36
- retry?: RetryConfig;
37
- } & core.RedisOptions;
18
+ } & core.RedisOptions & RequesterConfig;
38
19
  /**
39
20
  * Serverless redis client for upstash.
40
21
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -29,11 +29,8 @@ export declare type RedisConfigNodejs = {
29
29
  * }
30
30
  * ```
31
31
  */
32
- /**
33
- * Configure the retry behaviour in case of network errors
34
- */
35
- retry?: RetryConfig;
36
- } & core.RedisOptions;
32
+ agent?: any;
33
+ } & core.RedisOptions & RequesterConfig;
37
34
  /**
38
35
  * Serverless redis client for upstash.
39
36
  */
@@ -0,0 +1 @@
1
+ export declare const VERSION = "v0.0.0-ci.8500f14d-20221123";