@upstash/redis 0.0.0-ci.c37cc01e → 0.0.0-ci.c586e271-20221116
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 +0 -21
- package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
- package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
- package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
- package/esm/pkg/commands/getdel.js +9 -0
- package/esm/pkg/commands/mod.js +1 -0
- package/esm/pkg/commands/scan.js +3 -0
- package/esm/pkg/commands/set.js +16 -4
- package/esm/pkg/commands/zmscore.js +10 -0
- package/esm/pkg/http.js +73 -2
- package/esm/pkg/pipeline.js +33 -6
- package/esm/pkg/redis.js +48 -2
- package/esm/pkg/script.js +77 -0
- package/esm/platforms/cloudflare.js +1 -0
- package/esm/platforms/fastly.js +1 -0
- package/esm/platforms/node_with_fetch.js +2 -1
- package/esm/platforms/nodejs.js +2 -1
- package/package.json +1 -39
- package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
- package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
- package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
- package/script/pkg/commands/getdel.js +13 -0
- package/script/pkg/commands/mod.js +1 -0
- package/script/pkg/commands/scan.js +3 -0
- package/script/pkg/commands/set.js +16 -4
- package/script/pkg/commands/zmscore.js +14 -0
- package/script/pkg/http.js +73 -2
- package/script/pkg/pipeline.js +32 -5
- package/script/pkg/redis.js +47 -1
- package/script/pkg/script.js +81 -0
- package/script/platforms/cloudflare.js +1 -0
- package/script/platforms/fastly.js +1 -0
- package/script/platforms/node_with_fetch.js +2 -1
- package/script/platforms/nodejs.js +2 -1
- package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
- package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
- package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
- package/types/pkg/commands/getdel.d.ts +7 -0
- package/types/pkg/commands/mod.d.ts +1 -0
- package/types/pkg/commands/scan.d.ts +1 -0
- package/types/pkg/commands/set.d.ts +31 -2
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/http.d.ts +35 -4
- package/types/pkg/pipeline.d.ts +16 -3
- package/types/pkg/redis.d.ts +21 -1
- package/types/pkg/script.d.ts +42 -0
- package/types/platforms/cloudflare.d.ts +3 -6
- package/types/platforms/fastly.d.ts +2 -6
- package/types/platforms/node_with_fetch.d.ts +2 -21
- package/types/platforms/nodejs.d.ts +3 -6
package/types/pkg/pipeline.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
*/
|
|
@@ -374,7 +383,7 @@ export declare class Pipeline {
|
|
|
374
383
|
/**
|
|
375
384
|
* @see https://redis.io/commands/set
|
|
376
385
|
*/
|
|
377
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
386
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => this;
|
|
378
387
|
/**
|
|
379
388
|
* @see https://redis.io/commands/setbit
|
|
380
389
|
*/
|
|
@@ -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
|
*/
|
package/types/pkg/redis.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -354,7 +370,7 @@ export declare class Redis {
|
|
|
354
370
|
/**
|
|
355
371
|
* @see https://redis.io/commands/set
|
|
356
372
|
*/
|
|
357
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
373
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
|
|
358
374
|
/**
|
|
359
375
|
* @see https://redis.io/commands/setbit
|
|
360
376
|
*/
|
|
@@ -463,6 +479,10 @@ export declare class Redis {
|
|
|
463
479
|
* @see https://redis.io/commands/zlexcount
|
|
464
480
|
*/
|
|
465
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>;
|
|
466
486
|
/**
|
|
467
487
|
* @see https://redis.io/commands/zpopmax
|
|
468
488
|
*/
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Redis } from "./redis.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new script.
|
|
4
|
+
*
|
|
5
|
+
* Scripts offer the ability to optimistically try to execute a script without having to send the
|
|
6
|
+
* entire script to the server. If the script is loaded on the server, it tries again by sending
|
|
7
|
+
* the entire script. Afterwards, the script is cached on the server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const redis = new Redis({...})
|
|
12
|
+
*
|
|
13
|
+
* const script = redis.createScript<string>("return ARGV[1];")
|
|
14
|
+
* const arg1 = await script.eval([], ["Hello World"])
|
|
15
|
+
* assertEquals(arg1, "Hello World")
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class Script<TResult = unknown> {
|
|
19
|
+
readonly script: string;
|
|
20
|
+
readonly sha1: string;
|
|
21
|
+
private readonly redis;
|
|
22
|
+
constructor(redis: Redis, script: string);
|
|
23
|
+
/**
|
|
24
|
+
* Send an `EVAL` command to redis.
|
|
25
|
+
*/
|
|
26
|
+
eval(keys: string[], args: string[]): Promise<TResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the sha1 hash of the script and then calls `EVALSHA`.
|
|
29
|
+
*/
|
|
30
|
+
evalsha(keys: string[], args: string[]): Promise<TResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Optimistically try to run `EVALSHA` first.
|
|
33
|
+
* If the script is not loaded in redis, it will fall back and try again with `EVAL`.
|
|
34
|
+
*
|
|
35
|
+
* Following calls will be able to use the cached script
|
|
36
|
+
*/
|
|
37
|
+
exec(keys: string[], args: string[]): Promise<TResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Compute the sha1 hash of the script and return its hex representation.
|
|
40
|
+
*/
|
|
41
|
+
private digest;
|
|
42
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "../pkg/redis.js";
|
|
2
|
-
import type { Requester,
|
|
2
|
+
import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
|
|
3
|
+
import { RequesterConfig } from "../pkg/http.js";
|
|
3
4
|
export type { Requester, UpstashRequest, UpstashResponse };
|
|
4
5
|
/**
|
|
5
6
|
* Connection credentials for upstash redis.
|
|
@@ -14,11 +15,7 @@ export declare type RedisConfigCloudflare = {
|
|
|
14
15
|
* UPSTASH_REDIS_REST_TOKEN
|
|
15
16
|
*/
|
|
16
17
|
token: string;
|
|
17
|
-
|
|
18
|
-
* Configure the retry behaviour in case of network errors
|
|
19
|
-
*/
|
|
20
|
-
retry?: RetryConfig;
|
|
21
|
-
} & core.RedisOptions;
|
|
18
|
+
} & core.RedisOptions & RequesterConfig;
|
|
22
19
|
/**
|
|
23
20
|
* Serverless redis client for upstash.
|
|
24
21
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "../pkg/redis.js";
|
|
2
|
-
import type { Requester,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
*/
|