@upstash/redis 0.0.0-ci.e730ad54-20220901 → 0.0.0-ci.ec2c4106-20221122

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 verrsion
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";
@@ -1,11 +1,10 @@
1
1
  import { Command } from "./command.js";
2
2
  /**
3
- * @see https://redis.io/commands/zscore
3
+ * @see https://redis.io/commands/zmscore
4
4
  */
5
5
  export class ZMScoreCommand extends Command {
6
6
  constructor(cmd, opts) {
7
7
  const [key, members] = cmd;
8
- console.log({ key, members });
9
8
  super(["zmscore", key, ...members], opts);
10
9
  }
11
10
  }
package/esm/pkg/http.js CHANGED
@@ -25,9 +25,22 @@ 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
+ "Upstash-Telemetry-Runtime": config.telemetry?.runtime,
37
+ "Upstash-Telemetry-Platform": config.telemetry?.platform,
38
+ "Upstash-Telemetry-Sdk": config.telemetry?.sdk,
39
+ ...config.headers,
40
+ };
41
+ if (this.options.responseEncoding === "base64") {
42
+ this.headers["Upstash-Encoding"] = "base64";
43
+ }
31
44
  if (typeof config?.retry === "boolean" && config?.retry === false) {
32
45
  this.retry = {
33
46
  attempts: 1,
@@ -43,11 +56,19 @@ export class HttpClient {
43
56
  }
44
57
  }
45
58
  async request(req) {
59
+ const headers = Object.entries(this.headers).reduce((acc, [key, value]) => {
60
+ if (value) {
61
+ acc[key] = value;
62
+ }
63
+ return acc;
64
+ }, {});
65
+ console.log({ headers });
46
66
  const requestOptions = {
47
67
  method: "POST",
48
- headers: this.headers,
68
+ headers,
49
69
  body: JSON.stringify(req.body),
50
70
  keepalive: true,
71
+ agent: this.options?.agent,
51
72
  /**
52
73
  * Fastly specific
53
74
  */
@@ -72,6 +93,66 @@ export class HttpClient {
72
93
  if (!res.ok) {
73
94
  throw new UpstashError(body.error);
74
95
  }
96
+ if (this.options?.responseEncoding === "base64") {
97
+ return Array.isArray(body) ? body.map(decode) : decode(body);
98
+ }
75
99
  return body;
76
100
  }
77
101
  }
102
+ function base64decode(b64) {
103
+ let dec = "";
104
+ try {
105
+ /**
106
+ * Using only atob() is not enough because it doesn't work with unicode characters
107
+ */
108
+ const binString = atob(b64);
109
+ const size = binString.length;
110
+ const bytes = new Uint8Array(size);
111
+ for (let i = 0; i < size; i++) {
112
+ bytes[i] = binString.charCodeAt(i);
113
+ }
114
+ dec = new TextDecoder().decode(bytes);
115
+ }
116
+ catch {
117
+ dec = b64;
118
+ }
119
+ try {
120
+ return decodeURIComponent(dec);
121
+ }
122
+ catch {
123
+ return dec;
124
+ }
125
+ }
126
+ function decode(raw) {
127
+ let result = undefined;
128
+ switch (typeof raw.result) {
129
+ case "undefined":
130
+ return raw;
131
+ case "number": {
132
+ result = raw.result;
133
+ break;
134
+ }
135
+ case "object": {
136
+ if (Array.isArray(raw.result)) {
137
+ result = raw.result.map((v) => typeof v === "string"
138
+ ? base64decode(v)
139
+ : Array.isArray(v)
140
+ ? v.map(base64decode)
141
+ : v);
142
+ }
143
+ else {
144
+ // If it's not an array it must be null
145
+ // Apparently null is an object in javascript
146
+ result = null;
147
+ }
148
+ break;
149
+ }
150
+ case "string": {
151
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
152
+ break;
153
+ }
154
+ default:
155
+ break;
156
+ }
157
+ return { result, error: raw.error };
158
+ }
@@ -1,4 +1,4 @@
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
3
  import { ZMScoreCommand } from "./commands/zmscore.js";
4
4
  /**
@@ -17,7 +17,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
17
17
  * **Examples:**
18
18
  *
19
19
  * ```ts
20
- * const p = redis.pipeline()
20
+ * const p = redis.pipeline() // or redis.multi()
21
21
  * p.set("key","value")
22
22
  * p.get("key")
23
23
  * const res = await p.exec()
@@ -40,7 +40,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
40
40
  * ```
41
41
  */
42
42
  export class Pipeline {
43
- constructor(client, commandOptions) {
43
+ constructor(opts) {
44
44
  Object.defineProperty(this, "client", {
45
45
  enumerable: true,
46
46
  configurable: true,
@@ -59,6 +59,12 @@ export class Pipeline {
59
59
  writable: true,
60
60
  value: void 0
61
61
  });
62
+ Object.defineProperty(this, "multiExec", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
62
68
  /**
63
69
  * Send the pipeline request to upstash.
64
70
  *
@@ -77,8 +83,9 @@ export class Pipeline {
77
83
  if (this.commands.length === 0) {
78
84
  throw new Error("Pipeline is empty");
79
85
  }
86
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
80
87
  const res = (await this.client.request({
81
- path: ["pipeline"],
88
+ path,
82
89
  body: Object.values(this.commands).map((c) => c.command),
83
90
  }));
84
91
  return res.map(({ error, result }, i) => {
@@ -251,6 +258,15 @@ export class Pipeline {
251
258
  writable: true,
252
259
  value: (...args) => this.chain(new GetBitCommand(args, this.commandOptions))
253
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
+ });
254
270
  /**
255
271
  * @see https://redis.io/commands/getrange
256
272
  */
@@ -1129,9 +1145,10 @@ export class Pipeline {
1129
1145
  writable: true,
1130
1146
  value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
1131
1147
  });
1132
- this.client = client;
1148
+ this.client = opts.client;
1133
1149
  this.commands = [];
1134
- this.commandOptions = commandOptions;
1150
+ this.commandOptions = opts.commandOptions;
1151
+ this.multiExec = opts.multiExec ?? false;
1135
1152
  }
1136
1153
  /**
1137
1154
  * Pushes a command into the pipelien and returns a chainable instance of the
package/esm/pkg/redis.js CHANGED
@@ -1,4 +1,4 @@
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
4
  import { ZMScoreCommand } from "./commands/zmscore.js";
@@ -51,7 +51,30 @@ export class Redis {
51
51
  enumerable: true,
52
52
  configurable: true,
53
53
  writable: true,
54
- 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
+ })
55
78
  });
56
79
  /**
57
80
  * @see https://redis.io/commands/append
@@ -215,6 +238,15 @@ export class Redis {
215
238
  writable: true,
216
239
  value: (...args) => new GetBitCommand(args, this.opts).exec(this.client)
217
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
+ });
218
250
  /**
219
251
  * @see https://redis.io/commands/getrange
220
252
  */
@@ -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.ec2c4106-20221122";
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.e730ad54-20220901",
6
+ "version": "v0.0.0-ci.ec2c4106-20221122",
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);
@@ -3,12 +3,11 @@ 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) {
10
10
  const [key, members] = cmd;
11
- console.log({ key, members });
12
11
  super(["zmscore", key, ...members], opts);
13
12
  }
14
13
  }
@@ -28,9 +28,22 @@ 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
+ "Upstash-Telemetry-Runtime": config.telemetry?.runtime,
40
+ "Upstash-Telemetry-Platform": config.telemetry?.platform,
41
+ "Upstash-Telemetry-Sdk": config.telemetry?.sdk,
42
+ ...config.headers,
43
+ };
44
+ if (this.options.responseEncoding === "base64") {
45
+ this.headers["Upstash-Encoding"] = "base64";
46
+ }
34
47
  if (typeof config?.retry === "boolean" && config?.retry === false) {
35
48
  this.retry = {
36
49
  attempts: 1,
@@ -46,11 +59,19 @@ class HttpClient {
46
59
  }
47
60
  }
48
61
  async request(req) {
62
+ const headers = Object.entries(this.headers).reduce((acc, [key, value]) => {
63
+ if (value) {
64
+ acc[key] = value;
65
+ }
66
+ return acc;
67
+ }, {});
68
+ console.log({ headers });
49
69
  const requestOptions = {
50
70
  method: "POST",
51
- headers: this.headers,
71
+ headers,
52
72
  body: JSON.stringify(req.body),
53
73
  keepalive: true,
74
+ agent: this.options?.agent,
54
75
  /**
55
76
  * Fastly specific
56
77
  */
@@ -75,7 +96,67 @@ class HttpClient {
75
96
  if (!res.ok) {
76
97
  throw new error_js_1.UpstashError(body.error);
77
98
  }
99
+ if (this.options?.responseEncoding === "base64") {
100
+ return Array.isArray(body) ? body.map(decode) : decode(body);
101
+ }
78
102
  return body;
79
103
  }
80
104
  }
81
105
  exports.HttpClient = HttpClient;
106
+ function base64decode(b64) {
107
+ let dec = "";
108
+ try {
109
+ /**
110
+ * Using only atob() is not enough because it doesn't work with unicode characters
111
+ */
112
+ const binString = atob(b64);
113
+ const size = binString.length;
114
+ const bytes = new Uint8Array(size);
115
+ for (let i = 0; i < size; i++) {
116
+ bytes[i] = binString.charCodeAt(i);
117
+ }
118
+ dec = new TextDecoder().decode(bytes);
119
+ }
120
+ catch {
121
+ dec = b64;
122
+ }
123
+ try {
124
+ return decodeURIComponent(dec);
125
+ }
126
+ catch {
127
+ return dec;
128
+ }
129
+ }
130
+ function decode(raw) {
131
+ let result = undefined;
132
+ switch (typeof raw.result) {
133
+ case "undefined":
134
+ return raw;
135
+ case "number": {
136
+ result = raw.result;
137
+ break;
138
+ }
139
+ case "object": {
140
+ if (Array.isArray(raw.result)) {
141
+ result = raw.result.map((v) => typeof v === "string"
142
+ ? base64decode(v)
143
+ : Array.isArray(v)
144
+ ? v.map(base64decode)
145
+ : v);
146
+ }
147
+ else {
148
+ // If it's not an array it must be null
149
+ // Apparently null is an object in javascript
150
+ result = null;
151
+ }
152
+ break;
153
+ }
154
+ case "string": {
155
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
156
+ break;
157
+ }
158
+ default:
159
+ break;
160
+ }
161
+ return { result, error: raw.error };
162
+ }
@@ -20,7 +20,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
20
20
  * **Examples:**
21
21
  *
22
22
  * ```ts
23
- * const p = redis.pipeline()
23
+ * const p = redis.pipeline() // or redis.multi()
24
24
  * p.set("key","value")
25
25
  * p.get("key")
26
26
  * const res = await p.exec()
@@ -43,7 +43,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
43
43
  * ```
44
44
  */
45
45
  class Pipeline {
46
- constructor(client, commandOptions) {
46
+ constructor(opts) {
47
47
  Object.defineProperty(this, "client", {
48
48
  enumerable: true,
49
49
  configurable: true,
@@ -62,6 +62,12 @@ class Pipeline {
62
62
  writable: true,
63
63
  value: void 0
64
64
  });
65
+ Object.defineProperty(this, "multiExec", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
65
71
  /**
66
72
  * Send the pipeline request to upstash.
67
73
  *
@@ -80,8 +86,9 @@ class Pipeline {
80
86
  if (this.commands.length === 0) {
81
87
  throw new Error("Pipeline is empty");
82
88
  }
89
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
83
90
  const res = (await this.client.request({
84
- path: ["pipeline"],
91
+ path,
85
92
  body: Object.values(this.commands).map((c) => c.command),
86
93
  }));
87
94
  return res.map(({ error, result }, i) => {
@@ -254,6 +261,15 @@ class Pipeline {
254
261
  writable: true,
255
262
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
256
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
+ });
257
273
  /**
258
274
  * @see https://redis.io/commands/getrange
259
275
  */
@@ -1132,9 +1148,10 @@ class Pipeline {
1132
1148
  writable: true,
1133
1149
  value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
1134
1150
  });
1135
- this.client = client;
1151
+ this.client = opts.client;
1136
1152
  this.commands = [];
1137
- this.commandOptions = commandOptions;
1153
+ this.commandOptions = opts.commandOptions;
1154
+ this.multiExec = opts.multiExec ?? false;
1138
1155
  }
1139
1156
  /**
1140
1157
  * Pushes a command into the pipelien and returns a chainable instance of the
@@ -54,7 +54,30 @@ class Redis {
54
54
  enumerable: true,
55
55
  configurable: true,
56
56
  writable: true,
57
- 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
+ })
58
81
  });
59
82
  /**
60
83
  * @see https://redis.io/commands/append
@@ -218,6 +241,15 @@ class Redis {
218
241
  writable: true,
219
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
220
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
+ });
221
253
  /**
222
254
  * @see https://redis.io/commands/getrange
223
255
  */
@@ -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.ec2c4106-20221122";
@@ -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";
@@ -1,6 +1,6 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
- * @see https://redis.io/commands/zscore
3
+ * @see https://redis.io/commands/zmscore
4
4
  */
5
5
  export declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] | null> {
6
6
  constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
@@ -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
- headers: Record<string, string>;
44
- readonly options?: {
90
+ headers: Record<string, string | undefined>;
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
  */
@@ -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
  */
@@ -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.ec2c4106-20221122";