@upstash/redis 0.0.0-ci.5f29e95e → 0.0.0-ci.608697de-20221129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +14 -19
  2. package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
  3. package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
  4. package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
  5. package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
  6. package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
  7. package/esm/pkg/commands/getdel.js +9 -0
  8. package/esm/pkg/commands/hgetall.js +0 -4
  9. package/esm/pkg/commands/hrandfield.js +39 -0
  10. package/esm/pkg/commands/mod.js +2 -0
  11. package/esm/pkg/commands/scan.js +3 -0
  12. package/esm/pkg/commands/set.js +16 -4
  13. package/esm/pkg/commands/zmscore.js +10 -0
  14. package/esm/pkg/http.js +82 -2
  15. package/esm/pkg/pipeline.js +43 -6
  16. package/esm/pkg/redis.js +58 -2
  17. package/esm/pkg/script.js +77 -0
  18. package/esm/platforms/cloudflare.js +10 -2
  19. package/esm/platforms/fastly.js +1 -0
  20. package/esm/platforms/node_with_fetch.js +14 -1
  21. package/esm/platforms/nodejs.js +14 -1
  22. package/esm/version.js +1 -0
  23. package/package.json +1 -39
  24. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  25. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  26. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  27. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  28. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  29. package/script/pkg/commands/getdel.js +13 -0
  30. package/script/pkg/commands/hgetall.js +0 -4
  31. package/script/pkg/commands/hrandfield.js +43 -0
  32. package/script/pkg/commands/mod.js +2 -0
  33. package/script/pkg/commands/scan.js +3 -0
  34. package/script/pkg/commands/set.js +16 -4
  35. package/script/pkg/commands/zmscore.js +14 -0
  36. package/script/pkg/http.js +82 -2
  37. package/script/pkg/pipeline.js +42 -5
  38. package/script/pkg/redis.js +57 -1
  39. package/script/pkg/script.js +81 -0
  40. package/script/platforms/cloudflare.js +10 -2
  41. package/script/platforms/fastly.js +1 -0
  42. package/script/platforms/node_with_fetch.js +14 -1
  43. package/script/platforms/nodejs.js +14 -1
  44. package/script/version.js +4 -0
  45. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  46. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  47. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  48. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  49. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  50. package/types/pkg/commands/getdel.d.ts +7 -0
  51. package/types/pkg/commands/hrandfield.d.ts +9 -0
  52. package/types/pkg/commands/mod.d.ts +2 -0
  53. package/types/pkg/commands/scan.d.ts +1 -0
  54. package/types/pkg/commands/set.d.ts +31 -2
  55. package/types/pkg/commands/zmscore.d.ts +7 -0
  56. package/types/pkg/http.d.ts +52 -4
  57. package/types/pkg/pipeline.d.ts +20 -3
  58. package/types/pkg/redis.d.ts +29 -1
  59. package/types/pkg/script.d.ts +42 -0
  60. package/types/platforms/cloudflare.d.ts +8 -7
  61. package/types/platforms/fastly.d.ts +2 -6
  62. package/types/platforms/node_with_fetch.d.ts +2 -21
  63. package/types/platforms/nodejs.d.ts +3 -6
  64. package/types/version.d.ts +1 -0
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Redis = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const pipeline_js_1 = require("./pipeline.js");
6
+ const script_js_1 = require("./script.js");
7
+ const zmscore_js_1 = require("./commands/zmscore.js");
6
8
  /**
7
9
  * Serverless redis client for upstash.
8
10
  */
@@ -52,7 +54,30 @@ class Redis {
52
54
  enumerable: true,
53
55
  configurable: true,
54
56
  writable: true,
55
- 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
+ })
56
81
  });
57
82
  /**
58
83
  * @see https://redis.io/commands/append
@@ -216,6 +241,15 @@ class Redis {
216
241
  writable: true,
217
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
218
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
+ });
219
253
  /**
220
254
  * @see https://redis.io/commands/getrange
221
255
  */
@@ -324,6 +358,16 @@ class Redis {
324
358
  writable: true,
325
359
  value: (key, kv) => new mod_js_1.HMSetCommand([key, kv], this.opts).exec(this.client)
326
360
  });
361
+ /**
362
+ * @see https://redis.io/commands/hrandfield
363
+ */
364
+ Object.defineProperty(this, "hrandfield", {
365
+ enumerable: true,
366
+ configurable: true,
367
+ writable: true,
368
+ value: (key, count, withValues) => new mod_js_1.HRandFieldCommand([key, count, withValues], this.opts)
369
+ .exec(this.client)
370
+ });
327
371
  /**
328
372
  * @see https://redis.io/commands/hscan
329
373
  */
@@ -977,6 +1021,15 @@ class Redis {
977
1021
  writable: true,
978
1022
  value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
979
1023
  });
1024
+ /**
1025
+ * @see https://redis.io/commands/zmscore
1026
+ */
1027
+ Object.defineProperty(this, "zmscore", {
1028
+ enumerable: true,
1029
+ configurable: true,
1030
+ writable: true,
1031
+ value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
1032
+ });
980
1033
  /**
981
1034
  * @see https://redis.io/commands/zpopmax
982
1035
  */
@@ -1088,5 +1141,8 @@ class Redis {
1088
1141
  this.client = client;
1089
1142
  this.opts = opts;
1090
1143
  }
1144
+ createScript(script) {
1145
+ return new script_js_1.Script(this, script);
1146
+ }
1091
1147
  }
1092
1148
  exports.Redis = Redis;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Script = void 0;
4
+ const mod_js_1 = require("../deps/deno.land/x/sha1@v1.0.3/mod.js");
5
+ /**
6
+ * Creates a new script.
7
+ *
8
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
9
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
10
+ * the entire script. Afterwards, the script is cached on the server.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const redis = new Redis({...})
15
+ *
16
+ * const script = redis.createScript<string>("return ARGV[1];")
17
+ * const arg1 = await script.eval([], ["Hello World"])
18
+ * assertEquals(arg1, "Hello World")
19
+ * ```
20
+ */
21
+ class Script {
22
+ constructor(redis, script) {
23
+ Object.defineProperty(this, "script", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "sha1", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "redis", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ this.redis = redis;
42
+ this.sha1 = this.digest(script);
43
+ this.script = script;
44
+ }
45
+ /**
46
+ * Send an `EVAL` command to redis.
47
+ */
48
+ async eval(keys, args) {
49
+ return await this.redis.eval(this.script, keys, args);
50
+ }
51
+ /**
52
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
53
+ */
54
+ async evalsha(keys, args) {
55
+ return await this.redis.evalsha(this.sha1, keys, args);
56
+ }
57
+ /**
58
+ * Optimistically try to run `EVALSHA` first.
59
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
60
+ *
61
+ * Following calls will be able to use the cached script
62
+ */
63
+ async exec(keys, args) {
64
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (err) => {
65
+ if (err instanceof Error &&
66
+ err.message.toLowerCase().includes("noscript")) {
67
+ return await this.redis.eval(this.script, keys, args);
68
+ }
69
+ throw err;
70
+ });
71
+ return res;
72
+ }
73
+ /**
74
+ * Compute the sha1 hash of the script and return its hex representation.
75
+ */
76
+ digest(s) {
77
+ const hash = (0, mod_js_1.sha1)(s, "utf8", "hex");
78
+ return typeof hash === "string" ? hash : new TextDecoder().decode(hash);
79
+ }
80
+ }
81
+ exports.Script = Script;
@@ -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.608697de-20221129";
@@ -0,0 +1,5 @@
1
+ export declare function init(lookup: string[], revLookup: number[], urlsafe?: boolean): {
2
+ byteLength(b64: string): number;
3
+ toUint8Array(b64: string): Uint8Array;
4
+ fromUint8Array(buf: Uint8Array): string;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const byteLength: (b64: string) => number, toUint8Array: (b64: string) => Uint8Array, fromUint8Array: (buf: Uint8Array) => string;
@@ -0,0 +1 @@
1
+ export { encode, decode } from "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
@@ -0,0 +1,26 @@
1
+ /** Byte length of a SHA1 digest. */
2
+ export declare const BYTES: number;
3
+ /** A class representation of the SHA1 algorithm. */
4
+ export declare class SHA1 {
5
+ readonly hashSize: number;
6
+ private _buf;
7
+ private _bufIdx;
8
+ private _count;
9
+ private _K;
10
+ private _H;
11
+ private _finalized;
12
+ /** Creates a SHA1 instance. */
13
+ constructor();
14
+ /** Reduces the four input numbers to a single one. */
15
+ protected static F(t: number, b: number, c: number, d: number): number;
16
+ /** Initializes a hash instance. */
17
+ init(): SHA1;
18
+ /** Updates a hash with additional message data. */
19
+ update(msg: string | Uint8Array, inputEncoding?: string): SHA1;
20
+ /** Finalizes a hash with additional message data. */
21
+ digest(outputEncoding?: string): string | Uint8Array;
22
+ /** Performs one transformation cycle. */
23
+ private transform;
24
+ }
25
+ /** Generates a SHA1 hash of the input data. */
26
+ export declare function sha1(msg: string | Uint8Array, inputEncoding?: string, outputEncoding?: string): string | Uint8Array;
@@ -0,0 +1,3 @@
1
+ /** Decodes a Uint8Array to utf8-, base64-, or hex-encoded string. */
2
+ export declare function decode(buf: Uint8Array, encoding?: string): string;
3
+ export declare function encode(str: string, encoding?: string): Uint8Array;
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/hrandfield
4
+ */
5
+ export declare class HRandFieldCommand<TData extends string | string[] | Record<string, unknown>> extends Command<string | string[], TData> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<string, string>);
7
+ constructor(cmd: [key: string, count: number], opts?: CommandOptions<string[], string[]>);
8
+ constructor(cmd: [key: string, count: number, withValues: boolean], opts?: CommandOptions<string[], Partial<TData>>);
9
+ }
@@ -17,6 +17,7 @@ export * from "./flushall.js";
17
17
  export * from "./flushdb.js";
18
18
  export * from "./get.js";
19
19
  export * from "./getbit.js";
20
+ export * from "./getdel.js";
20
21
  export * from "./getrange.js";
21
22
  export * from "./getset.js";
22
23
  export * from "./hdel.js";
@@ -29,6 +30,7 @@ export * from "./hkeys.js";
29
30
  export * from "./hlen.js";
30
31
  export * from "./hmget.js";
31
32
  export * from "./hmset.js";
33
+ export * from "./hrandfield.js";
32
34
  export * from "./hscan.js";
33
35
  export * from "./hset.js";
34
36
  export * from "./hsetnx.js";
@@ -2,6 +2,7 @@ import { Command, CommandOptions } from "./command.js";
2
2
  export declare type ScanCommandOptions = {
3
3
  match?: string;
4
4
  count?: number;
5
+ type?: string;
5
6
  };
6
7
  /**
7
8
  * @see https://redis.io/commands/scan
@@ -1,13 +1,42 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
- export declare type SetCommandOptions = ({
2
+ export declare type SetCommandOptions = {
3
+ get: boolean;
4
+ } | ({
3
5
  ex: number;
4
6
  px?: never;
7
+ exat?: never;
8
+ pxat?: never;
9
+ keepTtl?: never;
5
10
  } | {
6
11
  ex?: never;
7
12
  px: number;
13
+ exat?: never;
14
+ pxat?: never;
15
+ keepTtl?: never;
8
16
  } | {
9
17
  ex?: never;
10
18
  px?: never;
19
+ exat: number;
20
+ pxat?: never;
21
+ keepTtl?: never;
22
+ } | {
23
+ ex?: never;
24
+ px?: never;
25
+ exat?: never;
26
+ pxat: number;
27
+ keepTtl?: never;
28
+ } | {
29
+ ex?: never;
30
+ px?: never;
31
+ exat?: never;
32
+ pxat?: never;
33
+ keepTtl: true;
34
+ } | {
35
+ ex?: never;
36
+ px?: never;
37
+ exat?: never;
38
+ pxat?: never;
39
+ keepTtl?: never;
11
40
  }) & ({
12
41
  nx: true;
13
42
  xx?: never;
@@ -21,6 +50,6 @@ export declare type SetCommandOptions = ({
21
50
  /**
22
51
  * @see https://redis.io/commands/set
23
52
  */
24
- export declare class SetCommand<TData, TResult = "OK"> extends Command<TResult, TData> {
53
+ export declare class SetCommand<TData, TResult = TData | "OK" | null> extends Command<TResult, TData | "OK" | null> {
25
54
  constructor([key, value, opts]: [key: string, value: TData, opts?: SetCommandOptions], cmdOpts?: CommandOptions<TResult, TData>);
26
55
  }
@@ -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
  */
@@ -188,6 +197,10 @@ export declare class Pipeline {
188
197
  hmset: <TData>(key: string, kv: {
189
198
  [field: string]: TData;
190
199
  }) => this;
200
+ /**
201
+ * @see https://redis.io/commands/hrandfield
202
+ */
203
+ hrandfield: <TData extends string | string[] | Record<string, unknown>>(key: string, count?: number, withValues?: boolean) => this;
191
204
  /**
192
205
  * @see https://redis.io/commands/hscan
193
206
  */
@@ -374,7 +387,7 @@ export declare class Pipeline {
374
387
  /**
375
388
  * @see https://redis.io/commands/set
376
389
  */
377
- set: <TData>(key: string, value: TData, opts?: SetCommandOptions | undefined) => this;
390
+ set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => this;
378
391
  /**
379
392
  * @see https://redis.io/commands/setbit
380
393
  */
@@ -483,6 +496,10 @@ export declare class Pipeline {
483
496
  * @see https://redis.io/commands/zlexcount
484
497
  */
485
498
  zlexcount: (key: string, min: string, max: string) => this;
499
+ /**
500
+ * @see https://redis.io/commands/zmscore
501
+ */
502
+ zmscore: (key: string, members: unknown[]) => this;
486
503
  /**
487
504
  * @see https://redis.io/commands/zpopmax
488
505
  */
@@ -2,6 +2,7 @@ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand
2
2
  import { Requester, UpstashRequest, UpstashResponse } from "./http.js";
3
3
  import { Pipeline } from "./pipeline.js";
4
4
  import type { CommandArgs } from "./types.js";
5
+ import { Script } from "./script.js";
5
6
  export declare type RedisOptions = {
6
7
  /**
7
8
  * Automatically try to deserialize the returned data from upstash using `JSON.deserialize`
@@ -32,12 +33,23 @@ export declare class Redis {
32
33
  * Wrap a new middleware around the HTTP client.
33
34
  */
34
35
  use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
36
+ createScript(script: string): Script;
35
37
  /**
36
38
  * Create a new pipeline that allows you to send requests in bulk.
37
39
  *
38
40
  * @see {@link Pipeline}
39
41
  */
40
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;
41
53
  /**
42
54
  * @see https://redis.io/commands/append
43
55
  */
@@ -115,6 +127,10 @@ export declare class Redis {
115
127
  * @see https://redis.io/commands/getbit
116
128
  */
117
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>;
118
134
  /**
119
135
  * @see https://redis.io/commands/getrange
120
136
  */
@@ -165,6 +181,14 @@ export declare class Redis {
165
181
  hmset: <TData>(key: string, kv: {
166
182
  [field: string]: TData;
167
183
  }) => Promise<"OK">;
184
+ /**
185
+ * @see https://redis.io/commands/hrandfield
186
+ */
187
+ hrandfield: {
188
+ (key: string): Promise<string>;
189
+ (key: string, count: number): Promise<string[]>;
190
+ <TData extends Record<string, unknown>>(key: string, count: number, withValues: boolean): Promise<Partial<TData>>;
191
+ };
168
192
  /**
169
193
  * @see https://redis.io/commands/hscan
170
194
  */
@@ -354,7 +378,7 @@ export declare class Redis {
354
378
  /**
355
379
  * @see https://redis.io/commands/set
356
380
  */
357
- set: <TData>(key: string, value: TData, opts?: SetCommandOptions | undefined) => Promise<TData>;
381
+ set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
358
382
  /**
359
383
  * @see https://redis.io/commands/setbit
360
384
  */
@@ -463,6 +487,10 @@ export declare class Redis {
463
487
  * @see https://redis.io/commands/zlexcount
464
488
  */
465
489
  zlexcount: (key: string, min: string, max: string) => Promise<number>;
490
+ /**
491
+ * @see https://redis.io/commands/zmscore
492
+ */
493
+ zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
466
494
  /**
467
495
  * @see https://redis.io/commands/zpopmax
468
496
  */