@upstash/redis 0.0.0-ci.e1d39d33 → 0.0.0-ci.efe72030

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 (47) hide show
  1. package/README.md +36 -274
  2. package/esm/pkg/commands/lpos.js +19 -0
  3. package/esm/pkg/commands/mod.js +1 -0
  4. package/esm/pkg/commands/script_exists.js +1 -10
  5. package/esm/pkg/commands/sdiffstore.js +1 -1
  6. package/esm/pkg/commands/zrange.js +6 -0
  7. package/esm/pkg/http.js +35 -7
  8. package/esm/pkg/pipeline.js +10 -1
  9. package/esm/pkg/redis.js +22 -1
  10. package/esm/platforms/cloudflare.js +5 -25
  11. package/esm/platforms/fastly.js +4 -25
  12. package/esm/platforms/node_with_fetch.js +4 -25
  13. package/esm/platforms/nodejs.js +4 -25
  14. package/package.json +24 -13
  15. package/script/pkg/commands/lpos.js +23 -0
  16. package/script/pkg/commands/mod.js +1 -0
  17. package/script/pkg/commands/script_exists.js +1 -10
  18. package/script/pkg/commands/sdiffstore.js +1 -1
  19. package/script/pkg/commands/zrange.js +6 -0
  20. package/script/pkg/http.js +35 -7
  21. package/script/pkg/pipeline.js +9 -0
  22. package/script/pkg/redis.js +21 -0
  23. package/script/platforms/cloudflare.js +5 -25
  24. package/script/platforms/fastly.js +4 -25
  25. package/script/platforms/node_with_fetch.js +4 -25
  26. package/script/platforms/nodejs.js +4 -25
  27. package/types/pkg/commands/bitop.d.ts +0 -1
  28. package/types/pkg/commands/bitpos.d.ts +1 -1
  29. package/types/pkg/commands/hmset.d.ts +2 -2
  30. package/types/pkg/commands/lpop.d.ts +1 -1
  31. package/types/pkg/commands/lpos.d.ts +15 -0
  32. package/types/pkg/commands/mget.d.ts +1 -1
  33. package/types/pkg/commands/mod.d.ts +1 -0
  34. package/types/pkg/commands/rpop.d.ts +2 -2
  35. package/types/pkg/commands/script_exists.d.ts +2 -4
  36. package/types/pkg/commands/sdiffstore.d.ts +1 -1
  37. package/types/pkg/commands/sinterstore.d.ts +2 -2
  38. package/types/pkg/commands/spop.d.ts +2 -2
  39. package/types/pkg/commands/zadd.d.ts +1 -1
  40. package/types/pkg/commands/zrange.d.ts +7 -0
  41. package/types/pkg/http.d.ts +27 -3
  42. package/types/pkg/pipeline.d.ts +14 -6
  43. package/types/pkg/redis.d.ts +22 -10
  44. package/types/platforms/cloudflare.d.ts +6 -2
  45. package/types/platforms/fastly.d.ts +5 -1
  46. package/types/platforms/node_with_fetch.d.ts +20 -1
  47. package/types/platforms/nodejs.d.ts +20 -1
@@ -1,6 +1,6 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
- * @see https://redis.io/commands/sdiffstpre
3
+ * @see https://redis.io/commands/sdiffstore
4
4
  */
5
5
  export declare class SDiffStoreCommand extends Command<number, number> {
6
6
  constructor(cmd: [destination: string, ...keys: string[]], opts?: CommandOptions<number, number>);
@@ -2,6 +2,6 @@ import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
3
  * @see https://redis.io/commands/sinterstore
4
4
  */
5
- export declare class SInterStoreCommand<TData = string> extends Command<unknown[], TData[]> {
6
- constructor(cmd: [destination: string, key: string, ...keys: string[]], opts?: CommandOptions<unknown[], TData[]>);
5
+ export declare class SInterStoreCommand extends Command<number, number> {
6
+ constructor(cmd: [destination: string, key: string, ...keys: string[]], opts?: CommandOptions<number, number>);
7
7
  }
@@ -2,6 +2,6 @@ import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
3
  * @see https://redis.io/commands/spop
4
4
  */
5
- export declare class SPopCommand<TData = number> extends Command<string | null, TData | null> {
6
- constructor([key, count]: [key: string, count?: number], opts?: CommandOptions<string | null, TData | null>);
5
+ export declare class SPopCommand<TData> extends Command<string | string[] | null, TData | null> {
6
+ constructor([key, count]: [key: string, count?: number], opts?: CommandOptions<string | string[] | null, TData | null>);
7
7
  }
@@ -30,6 +30,6 @@ export declare class ZAddCommand<TData = string> extends Command<number | null,
30
30
  constructor(cmd: [
31
31
  key: string,
32
32
  opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr,
33
- ...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]
33
+ ...scoreMemberPairs: ScoreMember<TData>[]
34
34
  ], opts?: CommandOptions<number | null, number | null>);
35
35
  }
@@ -1,6 +1,7 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  export declare type ZRangeCommandOptions = {
3
3
  withScores?: boolean;
4
+ rev?: boolean;
4
5
  } & ({
5
6
  byScore: true;
6
7
  byLex?: never;
@@ -10,6 +11,12 @@ export declare type ZRangeCommandOptions = {
10
11
  } | {
11
12
  byScore?: never;
12
13
  byLex?: never;
14
+ }) & ({
15
+ offset: number;
16
+ count: number;
17
+ } | {
18
+ offset?: never;
19
+ count?: never;
13
20
  });
14
21
  /**
15
22
  * @see https://redis.io/commands/zrange
@@ -12,12 +12,31 @@ export declare type UpstashResponse<TResult> = {
12
12
  export interface Requester {
13
13
  request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
14
14
  }
15
+ export declare type RetryConfig = false | {
16
+ /**
17
+ * The number of retries to attempt before giving up.
18
+ *
19
+ * @default 5
20
+ */
21
+ retries?: number;
22
+ /**
23
+ * A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
24
+ *
25
+ * @default
26
+ * ```ts
27
+ * Math.exp(retryCount) * 50
28
+ * ```
29
+ */
30
+ backoff?: (retryCount: number) => number;
31
+ };
32
+ declare type Options = {
33
+ backend?: string;
34
+ };
15
35
  export declare type HttpClientConfig = {
16
36
  headers?: Record<string, string>;
17
37
  baseUrl: string;
18
- options?: {
19
- backend?: string;
20
- };
38
+ options?: Options;
39
+ retry?: RetryConfig;
21
40
  };
22
41
  export declare class HttpClient implements Requester {
23
42
  baseUrl: string;
@@ -25,6 +44,11 @@ export declare class HttpClient implements Requester {
25
44
  readonly options?: {
26
45
  backend?: string;
27
46
  };
47
+ readonly retry: {
48
+ attempts: number;
49
+ backoff: (retryCount: number) => number;
50
+ };
28
51
  constructor(config: HttpClientConfig);
29
52
  request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
30
53
  }
54
+ export {};
@@ -1,4 +1,4 @@
1
- import { DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
1
+ import { DelCommand, ExistsCommand, FlushAllCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
2
  import { CommandOptions } from "./commands/command.js";
3
3
  import { Requester } from "./http.js";
4
4
  import { CommandArgs } from "./types.js";
@@ -79,7 +79,7 @@ export declare class Pipeline {
79
79
  /**
80
80
  * @see https://redis.io/commands/bitpos
81
81
  */
82
- bitpos: (key: string, start: number, end: number) => this;
82
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => this;
83
83
  /**
84
84
  * @see https://redis.io/commands/dbsize
85
85
  */
@@ -241,7 +241,15 @@ export declare class Pipeline {
241
241
  /**
242
242
  * @see https://redis.io/commands/lpop
243
243
  */
244
- lpop: <TData>(key: string) => this;
244
+ lpop: <TData>(key: string, count?: number | undefined) => this;
245
+ /**
246
+ * @see https://redis.io/commands/lpos
247
+ */
248
+ lpos: <TData>(key: string, element: unknown, opts?: {
249
+ rank?: number | undefined;
250
+ count?: number | undefined;
251
+ maxLen?: number | undefined;
252
+ } | undefined) => this;
245
253
  /**
246
254
  * @see https://redis.io/commands/lpush
247
255
  */
@@ -269,7 +277,7 @@ export declare class Pipeline {
269
277
  /**
270
278
  * @see https://redis.io/commands/mget
271
279
  */
272
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => this;
280
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => this;
273
281
  /**
274
282
  * @see https://redis.io/commands/mset
275
283
  */
@@ -325,7 +333,7 @@ export declare class Pipeline {
325
333
  /**
326
334
  * @see https://redis.io/commands/rpop
327
335
  */
328
- rpop: <TData = string>(key: string) => this;
336
+ rpop: <TData = string>(key: string, count?: number | undefined) => this;
329
337
  /**
330
338
  * @see https://redis.io/commands/rpush
331
339
  */
@@ -349,7 +357,7 @@ export declare class Pipeline {
349
357
  /**
350
358
  * @see https://redis.io/commands/script-exists
351
359
  */
352
- scriptExists: (args_0: string, ...args_1: string[]) => this;
360
+ scriptExists: (...args: CommandArgs<typeof ScriptExistsCommand>) => this;
353
361
  /**
354
362
  * @see https://redis.io/commands/script-flush
355
363
  */
@@ -1,5 +1,5 @@
1
- import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
- import { Requester } from "./http.js";
1
+ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
+ import { Requester, UpstashRequest, UpstashResponse } from "./http.js";
3
3
  import { Pipeline } from "./pipeline.js";
4
4
  import type { CommandArgs } from "./types.js";
5
5
  export declare type RedisOptions = {
@@ -14,7 +14,7 @@ export declare type RedisOptions = {
14
14
  * Serverless redis client for upstash.
15
15
  */
16
16
  export declare class Redis {
17
- protected readonly client: Requester;
17
+ protected client: Requester;
18
18
  protected opts?: CommandOptions<any, any>;
19
19
  /**
20
20
  * Create a new redis client
@@ -28,6 +28,10 @@ export declare class Redis {
28
28
  * ```
29
29
  */
30
30
  constructor(client: Requester, opts?: RedisOptions);
31
+ /**
32
+ * Wrap a new middleware around the HTTP client.
33
+ */
34
+ use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
31
35
  /**
32
36
  * Create a new pipeline that allows you to send requests in bulk.
33
37
  *
@@ -52,7 +56,7 @@ export declare class Redis {
52
56
  /**
53
57
  * @see https://redis.io/commands/bitpos
54
58
  */
55
- bitpos: (key: string, start: number, end: number) => Promise<number>;
59
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => Promise<number>;
56
60
  /**
57
61
  * @see https://redis.io/commands/dbsize
58
62
  */
@@ -160,7 +164,7 @@ export declare class Redis {
160
164
  */
161
165
  hmset: <TData>(key: string, kv: {
162
166
  [field: string]: TData;
163
- }) => Promise<number>;
167
+ }) => Promise<"OK">;
164
168
  /**
165
169
  * @see https://redis.io/commands/hscan
166
170
  */
@@ -214,7 +218,15 @@ export declare class Redis {
214
218
  /**
215
219
  * @see https://redis.io/commands/lpop
216
220
  */
217
- lpop: <TData>(key: string) => Promise<TData | null>;
221
+ lpop: <TData>(key: string, count?: number | undefined) => Promise<TData | null>;
222
+ /**
223
+ * @see https://redis.io/commands/lpos
224
+ */
225
+ lpos: <TData = number>(key: string, element: unknown, opts?: {
226
+ rank?: number | undefined;
227
+ count?: number | undefined;
228
+ maxLen?: number | undefined;
229
+ } | undefined) => Promise<TData>;
218
230
  /**
219
231
  * @see https://redis.io/commands/lpush
220
232
  */
@@ -242,7 +254,7 @@ export declare class Redis {
242
254
  /**
243
255
  * @see https://redis.io/commands/mget
244
256
  */
245
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => Promise<TData>;
257
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => Promise<TData>;
246
258
  /**
247
259
  * @see https://redis.io/commands/mset
248
260
  */
@@ -298,7 +310,7 @@ export declare class Redis {
298
310
  /**
299
311
  * @see https://redis.io/commands/rpop
300
312
  */
301
- rpop: <TData = string>(key: string) => Promise<TData | null>;
313
+ rpop: <TData = string>(key: string, count?: number | undefined) => Promise<TData | null>;
302
314
  /**
303
315
  * @see https://redis.io/commands/rpush
304
316
  */
@@ -322,7 +334,7 @@ export declare class Redis {
322
334
  /**
323
335
  * @see https://redis.io/commands/script-exists
324
336
  */
325
- scriptExists: (args_0: string, ...args_1: string[]) => Promise<[]>;
337
+ scriptExists: (...args: CommandArgs<typeof ScriptExistsCommand>) => Promise<number[]>;
326
338
  /**
327
339
  * @see https://redis.io/commands/script-flush
328
340
  */
@@ -366,7 +378,7 @@ export declare class Redis {
366
378
  /**
367
379
  * @see https://redis.io/commands/sinterstore
368
380
  */
369
- sinterstore: (destination: string, key: string, ...keys: string[]) => Promise<string[]>;
381
+ sinterstore: (destination: string, key: string, ...keys: string[]) => Promise<number>;
370
382
  /**
371
383
  * @see https://redis.io/commands/sismember
372
384
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -14,6 +14,10 @@ export declare type RedisConfigCloudflare = {
14
14
  * UPSTASH_REDIS_REST_TOKEN
15
15
  */
16
16
  token: string;
17
+ /**
18
+ * Configure the retry behaviour in case of network errors
19
+ */
20
+ retry?: RetryConfig;
17
21
  } & core.RedisOptions;
18
22
  /**
19
23
  * Serverless redis client for upstash.
@@ -34,5 +38,5 @@ export declare class Redis extends core.Redis {
34
38
  static fromEnv(env?: {
35
39
  UPSTASH_REDIS_REST_URL: string;
36
40
  UPSTASH_REDIS_REST_TOKEN: string;
37
- }): Redis;
41
+ }, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
38
42
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -20,6 +20,10 @@ 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;
23
27
  } & core.RedisOptions;
24
28
  /**
25
29
  * Serverless redis client for upstash.
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  import "isomorphic-fetch";
4
4
  export type { Requester, UpstashRequest, UpstashResponse };
5
5
  /**
@@ -15,6 +15,25 @@ 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;
18
37
  } & core.RedisOptions;
19
38
  /**
20
39
  * Serverless redis client for upstash.
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -14,6 +14,25 @@ export declare type RedisConfigNodejs = {
14
14
  * UPSTASH_REDIS_REST_TOKEN
15
15
  */
16
16
  token: string;
17
+ /**
18
+ * An agent allows you to reuse connections to reduce latency for multiple sequential requests.
19
+ *
20
+ * This is a node specific implementation and is not supported in various runtimes like Vercel
21
+ * edge functions.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import https from "https"
26
+ *
27
+ * const options: RedisConfigNodejs = {
28
+ * agent: new https.Agent({ keepAlive: true })
29
+ * }
30
+ * ```
31
+ */
32
+ /**
33
+ * Configure the retry behaviour in case of network errors
34
+ */
35
+ retry?: RetryConfig;
17
36
  } & core.RedisOptions;
18
37
  /**
19
38
  * Serverless redis client for upstash.