@upstash/redis 0.0.0-ci.df9c9bb7 → 0.0.0-ci.e0fa2b9d-20230419
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 +20 -18
- 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/command.js +12 -3
- package/esm/pkg/commands/getdel.js +9 -0
- package/esm/pkg/commands/hgetall.js +0 -4
- package/esm/pkg/commands/hrandfield.js +39 -0
- package/esm/pkg/commands/json_arrappend.js +9 -0
- package/esm/pkg/commands/json_arrindex.js +9 -0
- package/esm/pkg/commands/json_arrinsert.js +9 -0
- package/esm/pkg/commands/json_arrlen.js +9 -0
- package/esm/pkg/commands/json_arrpop.js +9 -0
- package/esm/pkg/commands/json_arrtrim.js +12 -0
- package/esm/pkg/commands/json_clear.js +9 -0
- package/esm/pkg/commands/json_del.js +9 -0
- package/esm/pkg/commands/json_forget.js +9 -0
- package/esm/pkg/commands/json_get.js +30 -0
- package/esm/pkg/commands/json_mget.js +9 -0
- package/esm/pkg/commands/json_numincrby.js +9 -0
- package/esm/pkg/commands/json_nummultby.js +9 -0
- package/esm/pkg/commands/json_objkeys.js +9 -0
- package/esm/pkg/commands/json_objlen.js +9 -0
- package/esm/pkg/commands/json_resp.js +9 -0
- package/esm/pkg/commands/json_set.js +18 -0
- package/esm/pkg/commands/json_strappend.js +9 -0
- package/esm/pkg/commands/json_strlen.js +9 -0
- package/esm/pkg/commands/json_toggle.js +9 -0
- package/esm/pkg/commands/json_type.js +9 -0
- package/esm/pkg/commands/lmove.js +9 -0
- package/esm/pkg/commands/mod.js +25 -0
- package/esm/pkg/commands/scan.js +3 -0
- package/esm/pkg/commands/set.js +16 -4
- package/esm/pkg/commands/smismember.js +9 -0
- package/esm/pkg/commands/zdiffstore.js +9 -0
- package/esm/pkg/commands/zmscore.js +10 -0
- package/esm/pkg/http.js +92 -2
- package/esm/pkg/pipeline.js +163 -6
- package/esm/pkg/redis.js +202 -2
- package/esm/pkg/script.js +77 -0
- package/esm/platforms/cloudflare.js +10 -2
- package/esm/platforms/fastly.js +6 -0
- package/esm/platforms/node_with_fetch.js +26 -1
- package/esm/platforms/nodejs.js +22 -1
- package/esm/version.js +1 -0
- package/package.json +41 -54
- 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/command.js +12 -3
- package/script/pkg/commands/getdel.js +13 -0
- package/script/pkg/commands/hgetall.js +0 -4
- package/script/pkg/commands/hrandfield.js +43 -0
- package/script/pkg/commands/json_arrappend.js +13 -0
- package/script/pkg/commands/json_arrindex.js +13 -0
- package/script/pkg/commands/json_arrinsert.js +13 -0
- package/script/pkg/commands/json_arrlen.js +13 -0
- package/script/pkg/commands/json_arrpop.js +13 -0
- package/script/pkg/commands/json_arrtrim.js +16 -0
- package/script/pkg/commands/json_clear.js +13 -0
- package/script/pkg/commands/json_del.js +13 -0
- package/script/pkg/commands/json_forget.js +13 -0
- package/script/pkg/commands/json_get.js +34 -0
- package/script/pkg/commands/json_mget.js +13 -0
- package/script/pkg/commands/json_numincrby.js +13 -0
- package/script/pkg/commands/json_nummultby.js +13 -0
- package/script/pkg/commands/json_objkeys.js +13 -0
- package/script/pkg/commands/json_objlen.js +13 -0
- package/script/pkg/commands/json_resp.js +13 -0
- package/script/pkg/commands/json_set.js +22 -0
- package/script/pkg/commands/json_strappend.js +13 -0
- package/script/pkg/commands/json_strlen.js +13 -0
- package/script/pkg/commands/json_toggle.js +13 -0
- package/script/pkg/commands/json_type.js +13 -0
- package/script/pkg/commands/lmove.js +13 -0
- package/script/pkg/commands/mod.js +25 -0
- package/script/pkg/commands/scan.js +3 -0
- package/script/pkg/commands/set.js +16 -4
- package/script/pkg/commands/smismember.js +13 -0
- package/script/pkg/commands/zdiffstore.js +13 -0
- package/script/pkg/commands/zmscore.js +14 -0
- package/script/pkg/http.js +92 -2
- package/script/pkg/pipeline.js +162 -5
- package/script/pkg/redis.js +201 -1
- package/script/pkg/script.js +81 -0
- package/script/platforms/cloudflare.js +10 -2
- package/script/platforms/fastly.js +6 -0
- package/script/platforms/node_with_fetch.js +26 -1
- package/script/platforms/nodejs.js +22 -1
- package/script/version.js +4 -0
- 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/bitop.d.ts +0 -1
- package/types/pkg/commands/command.d.ts +5 -5
- package/types/pkg/commands/getdel.d.ts +7 -0
- package/types/pkg/commands/hrandfield.d.ts +9 -0
- package/types/pkg/commands/json_arrappend.d.ts +7 -0
- package/types/pkg/commands/json_arrindex.d.ts +13 -0
- package/types/pkg/commands/json_arrinsert.d.ts +7 -0
- package/types/pkg/commands/json_arrlen.d.ts +7 -0
- package/types/pkg/commands/json_arrpop.d.ts +7 -0
- package/types/pkg/commands/json_arrtrim.d.ts +7 -0
- package/types/pkg/commands/json_clear.d.ts +7 -0
- package/types/pkg/commands/json_del.d.ts +7 -0
- package/types/pkg/commands/json_forget.d.ts +7 -0
- package/types/pkg/commands/json_get.d.ts +15 -0
- package/types/pkg/commands/json_mget.d.ts +7 -0
- package/types/pkg/commands/json_numincrby.d.ts +7 -0
- package/types/pkg/commands/json_nummultby.d.ts +7 -0
- package/types/pkg/commands/json_objkeys.d.ts +7 -0
- package/types/pkg/commands/json_objlen.d.ts +7 -0
- package/types/pkg/commands/json_resp.d.ts +7 -0
- package/types/pkg/commands/json_set.d.ts +18 -0
- package/types/pkg/commands/json_strappend.d.ts +7 -0
- package/types/pkg/commands/json_strlen.d.ts +7 -0
- package/types/pkg/commands/json_toggle.d.ts +7 -0
- package/types/pkg/commands/json_type.d.ts +7 -0
- package/types/pkg/commands/lmove.d.ts +12 -0
- package/types/pkg/commands/mget.d.ts +1 -1
- package/types/pkg/commands/mod.d.ts +25 -0
- package/types/pkg/commands/scan.d.ts +2 -1
- package/types/pkg/commands/script_flush.d.ts +1 -1
- package/types/pkg/commands/set.d.ts +31 -2
- package/types/pkg/commands/smembers.d.ts +2 -2
- package/types/pkg/commands/smismember.d.ts +7 -0
- package/types/pkg/commands/type.d.ts +1 -1
- package/types/pkg/commands/zadd.d.ts +4 -4
- package/types/pkg/commands/zdiffstore.d.ts +7 -0
- package/types/pkg/commands/zinterstore.d.ts +1 -1
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/commands/zrange.d.ts +1 -1
- package/types/pkg/commands/zunionstore.d.ts +1 -1
- package/types/pkg/http.d.ts +44 -7
- package/types/pkg/pipeline.d.ts +61 -6
- package/types/pkg/redis.d.ts +143 -12
- package/types/pkg/script.d.ts +42 -0
- package/types/pkg/types.d.ts +27 -1
- package/types/platforms/cloudflare.d.ts +9 -8
- package/types/platforms/fastly.d.ts +3 -7
- package/types/platforms/node_with_fetch.d.ts +3 -22
- package/types/platforms/nodejs.d.ts +4 -7
- package/types/version.d.ts +1 -0
package/types/pkg/http.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { Telemetry } from "./types.js";
|
|
2
|
+
type CacheSetting = "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload";
|
|
3
|
+
export type UpstashRequest = {
|
|
2
4
|
path?: string[];
|
|
3
5
|
/**
|
|
4
6
|
* Request body will be serialized to json
|
|
5
7
|
*/
|
|
6
8
|
body?: unknown;
|
|
7
9
|
};
|
|
8
|
-
export
|
|
10
|
+
export type UpstashResponse<TResult> = {
|
|
9
11
|
result?: TResult;
|
|
10
12
|
error?: string;
|
|
11
13
|
};
|
|
12
14
|
export interface Requester {
|
|
13
15
|
request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
14
16
|
}
|
|
15
|
-
export
|
|
17
|
+
export type RetryConfig = false | {
|
|
16
18
|
/**
|
|
17
19
|
* The number of retries to attempt before giving up.
|
|
18
20
|
*
|
|
@@ -29,26 +31,61 @@ export declare type RetryConfig = false | {
|
|
|
29
31
|
*/
|
|
30
32
|
backoff?: (retryCount: number) => number;
|
|
31
33
|
};
|
|
32
|
-
|
|
34
|
+
export type Options = {
|
|
33
35
|
backend?: string;
|
|
34
36
|
};
|
|
35
|
-
export
|
|
37
|
+
export type RequesterConfig = {
|
|
38
|
+
/**
|
|
39
|
+
* Configure the retry behaviour in case of network errors
|
|
40
|
+
*/
|
|
41
|
+
retry?: RetryConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
|
|
44
|
+
* valid json and will therefore cause errors when deserializing. This used to happen very
|
|
45
|
+
* frequently with non-utf8 data, such as emojis.
|
|
46
|
+
*
|
|
47
|
+
* By default we will therefore encode the data as base64 on the server, before sending it to the
|
|
48
|
+
* client. The client will then decode the base64 data and parse it as utf8.
|
|
49
|
+
*
|
|
50
|
+
* For very large entries, this can add a few milliseconds, so if you are sure that your data is
|
|
51
|
+
* valid utf8, you can disable this behaviour by setting this option to false.
|
|
52
|
+
*
|
|
53
|
+
* Here's what the response body looks like:
|
|
54
|
+
*
|
|
55
|
+
* ```json
|
|
56
|
+
* {
|
|
57
|
+
* result?: "base64-encoded",
|
|
58
|
+
* error?: string
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @default "base64"
|
|
63
|
+
*/
|
|
64
|
+
responseEncoding?: false | "base64";
|
|
65
|
+
};
|
|
66
|
+
export type HttpClientConfig = {
|
|
36
67
|
headers?: Record<string, string>;
|
|
37
68
|
baseUrl: string;
|
|
38
69
|
options?: Options;
|
|
39
70
|
retry?: RetryConfig;
|
|
40
|
-
|
|
71
|
+
agent?: any;
|
|
72
|
+
cache?: CacheSetting;
|
|
73
|
+
} & RequesterConfig;
|
|
41
74
|
export declare class HttpClient implements Requester {
|
|
42
75
|
baseUrl: string;
|
|
43
76
|
headers: Record<string, string>;
|
|
44
|
-
readonly options
|
|
77
|
+
readonly options: {
|
|
45
78
|
backend?: string;
|
|
79
|
+
agent: any;
|
|
80
|
+
responseEncoding?: false | "base64";
|
|
81
|
+
cache?: CacheSetting;
|
|
46
82
|
};
|
|
47
83
|
readonly retry: {
|
|
48
84
|
attempts: number;
|
|
49
85
|
backoff: (retryCount: number) => number;
|
|
50
86
|
};
|
|
51
87
|
constructor(config: HttpClientConfig);
|
|
88
|
+
mergeTelemetry(telemetry: Telemetry): void;
|
|
52
89
|
request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
|
|
53
90
|
}
|
|
54
91
|
export {};
|
package/types/pkg/pipeline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
|
|
1
|
+
import { DelCommand, ExistsCommand, FlushAllCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, 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";
|
|
@@ -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
|
*
|
|
@@ -80,6 +85,10 @@ export declare class Pipeline {
|
|
|
80
85
|
* @see https://redis.io/commands/bitpos
|
|
81
86
|
*/
|
|
82
87
|
bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => this;
|
|
88
|
+
/**
|
|
89
|
+
* @see https://redis.io/commands/zdiffstore
|
|
90
|
+
*/
|
|
91
|
+
zdiffstore: (destination: string, numkeys: number, ...keys: string[]) => this;
|
|
83
92
|
/**
|
|
84
93
|
* @see https://redis.io/commands/dbsize
|
|
85
94
|
*/
|
|
@@ -138,6 +147,10 @@ export declare class Pipeline {
|
|
|
138
147
|
* @see https://redis.io/commands/getbit
|
|
139
148
|
*/
|
|
140
149
|
getbit: (key: string, offset: number) => this;
|
|
150
|
+
/**
|
|
151
|
+
* @see https://redis.io/commands/getdel
|
|
152
|
+
*/
|
|
153
|
+
getdel: <TData>(key: string) => this;
|
|
141
154
|
/**
|
|
142
155
|
* @see https://redis.io/commands/getrange
|
|
143
156
|
*/
|
|
@@ -188,6 +201,10 @@ export declare class Pipeline {
|
|
|
188
201
|
hmset: <TData>(key: string, kv: {
|
|
189
202
|
[field: string]: TData;
|
|
190
203
|
}) => this;
|
|
204
|
+
/**
|
|
205
|
+
* @see https://redis.io/commands/hrandfield
|
|
206
|
+
*/
|
|
207
|
+
hrandfield: <TData extends string | string[] | Record<string, unknown>>(key: string, count?: number, withValues?: boolean) => this;
|
|
191
208
|
/**
|
|
192
209
|
* @see https://redis.io/commands/hscan
|
|
193
210
|
*/
|
|
@@ -238,6 +255,10 @@ export declare class Pipeline {
|
|
|
238
255
|
* @see https://redis.io/commands/llen
|
|
239
256
|
*/
|
|
240
257
|
llen: (key: string) => this;
|
|
258
|
+
/**
|
|
259
|
+
* @see https://redis.io/commands/lmove
|
|
260
|
+
*/
|
|
261
|
+
lmove: <TData = string>(source: string, destination: string, whereFrom: "left" | "right", whereTo: "left" | "right") => this;
|
|
241
262
|
/**
|
|
242
263
|
* @see https://redis.io/commands/lpop
|
|
243
264
|
*/
|
|
@@ -277,7 +298,7 @@ export declare class Pipeline {
|
|
|
277
298
|
/**
|
|
278
299
|
* @see https://redis.io/commands/mget
|
|
279
300
|
*/
|
|
280
|
-
mget: <TData extends unknown[]>(
|
|
301
|
+
mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => this;
|
|
281
302
|
/**
|
|
282
303
|
* @see https://redis.io/commands/mset
|
|
283
304
|
*/
|
|
@@ -374,7 +395,7 @@ export declare class Pipeline {
|
|
|
374
395
|
/**
|
|
375
396
|
* @see https://redis.io/commands/set
|
|
376
397
|
*/
|
|
377
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
398
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => this;
|
|
378
399
|
/**
|
|
379
400
|
* @see https://redis.io/commands/setbit
|
|
380
401
|
*/
|
|
@@ -406,7 +427,11 @@ export declare class Pipeline {
|
|
|
406
427
|
/**
|
|
407
428
|
* @see https://redis.io/commands/smembers
|
|
408
429
|
*/
|
|
409
|
-
smembers: (key: string) => this;
|
|
430
|
+
smembers: <TData extends unknown[] = string[]>(key: string) => this;
|
|
431
|
+
/**
|
|
432
|
+
* @see https://redis.io/commands/smismember
|
|
433
|
+
*/
|
|
434
|
+
smismember: <TMembers extends unknown[]>(key: string, members: TMembers) => this;
|
|
410
435
|
/**
|
|
411
436
|
* @see https://redis.io/commands/smove
|
|
412
437
|
*/
|
|
@@ -483,6 +508,10 @@ export declare class Pipeline {
|
|
|
483
508
|
* @see https://redis.io/commands/zlexcount
|
|
484
509
|
*/
|
|
485
510
|
zlexcount: (key: string, min: string, max: string) => this;
|
|
511
|
+
/**
|
|
512
|
+
* @see https://redis.io/commands/zmscore
|
|
513
|
+
*/
|
|
514
|
+
zmscore: (key: string, members: unknown[]) => this;
|
|
486
515
|
/**
|
|
487
516
|
* @see https://redis.io/commands/zpopmax
|
|
488
517
|
*/
|
|
@@ -545,4 +574,30 @@ export declare class Pipeline {
|
|
|
545
574
|
* @see https://redis.io/commands/zunionstore
|
|
546
575
|
*/
|
|
547
576
|
zunionstore: (destination: string, numKeys: number, keys: string[], opts?: import("./commands/zunionstore.js").ZUnionStoreCommandOptions | undefined) => this;
|
|
577
|
+
/**
|
|
578
|
+
* @see https://redis.io/commands/?group=json
|
|
579
|
+
*/
|
|
580
|
+
get json(): {
|
|
581
|
+
arrappend: (...args: CommandArgs<typeof JsonArrAppendCommand>) => Pipeline;
|
|
582
|
+
arrindex: (...args: CommandArgs<typeof JsonArrIndexCommand>) => Pipeline;
|
|
583
|
+
arrinsert: (...args: CommandArgs<typeof JsonArrInsertCommand>) => Pipeline;
|
|
584
|
+
arrlen: (...args: CommandArgs<typeof JsonArrLenCommand>) => Pipeline;
|
|
585
|
+
arrpop: (...args: CommandArgs<typeof JsonArrPopCommand>) => Pipeline;
|
|
586
|
+
arrtrim: (...args: CommandArgs<typeof JsonArrTrimCommand>) => Pipeline;
|
|
587
|
+
clear: (...args: CommandArgs<typeof JsonClearCommand>) => Pipeline;
|
|
588
|
+
del: (...args: CommandArgs<typeof JsonDelCommand>) => Pipeline;
|
|
589
|
+
forget: (...args: CommandArgs<typeof JsonForgetCommand>) => Pipeline;
|
|
590
|
+
get: (...args: CommandArgs<typeof JsonGetCommand>) => Pipeline;
|
|
591
|
+
mget: (...args: CommandArgs<typeof JsonMGetCommand>) => Pipeline;
|
|
592
|
+
numincrby: (...args: CommandArgs<typeof JsonNumIncrByCommand>) => Pipeline;
|
|
593
|
+
nummultby: (...args: CommandArgs<typeof JsonNumMultByCommand>) => Pipeline;
|
|
594
|
+
objkeys: (...args: CommandArgs<typeof JsonObjKeysCommand>) => Pipeline;
|
|
595
|
+
objlen: (...args: CommandArgs<typeof JsonObjLenCommand>) => Pipeline;
|
|
596
|
+
resp: (...args: CommandArgs<typeof JsonRespCommand>) => Pipeline;
|
|
597
|
+
set: (...args: CommandArgs<typeof JsonSetCommand>) => Pipeline;
|
|
598
|
+
strappend: (...args: CommandArgs<typeof JsonStrAppendCommand>) => Pipeline;
|
|
599
|
+
strlen: (...args: CommandArgs<typeof JsonStrLenCommand>) => Pipeline;
|
|
600
|
+
toggle: (...args: CommandArgs<typeof JsonToggleCommand>) => Pipeline;
|
|
601
|
+
type: (...args: CommandArgs<typeof JsonTypeCommand>) => Pipeline;
|
|
602
|
+
};
|
|
548
603
|
}
|
package/types/pkg/redis.d.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
|
|
1
|
+
import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, JsonGetCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
automaticDeserialization?: boolean;
|
|
12
|
-
};
|
|
5
|
+
import { Script } from "./script.js";
|
|
6
|
+
import type { RedisOptions, Telemetry } from "./types.js";
|
|
7
|
+
export type { RedisOptions } from "./types.js";
|
|
13
8
|
/**
|
|
14
9
|
* Serverless redis client for upstash.
|
|
15
10
|
*/
|
|
16
11
|
export declare class Redis {
|
|
17
12
|
protected client: Requester;
|
|
18
13
|
protected opts?: CommandOptions<any, any>;
|
|
14
|
+
protected enableTelemetry: boolean;
|
|
19
15
|
/**
|
|
20
16
|
* Create a new redis client
|
|
21
17
|
*
|
|
@@ -28,16 +24,123 @@ export declare class Redis {
|
|
|
28
24
|
* ```
|
|
29
25
|
*/
|
|
30
26
|
constructor(client: Requester, opts?: RedisOptions);
|
|
27
|
+
get json(): {
|
|
28
|
+
/**
|
|
29
|
+
* @see https://redis.io/commands/json.arrappend
|
|
30
|
+
*/
|
|
31
|
+
arrappend: (key: string, path: string, ...values: unknown[]) => Promise<(number | null)[]>;
|
|
32
|
+
/**
|
|
33
|
+
* @see https://redis.io/commands/json.arrindex
|
|
34
|
+
*/
|
|
35
|
+
arrindex: (key: string, path: string, value: unknown, start?: number | undefined, stop?: number | undefined) => Promise<(number | null)[]>;
|
|
36
|
+
/**
|
|
37
|
+
* @see https://redis.io/commands/json.arrinsert
|
|
38
|
+
*/
|
|
39
|
+
arrinsert: (key: string, path: string, index: number, ...values: unknown[]) => Promise<(number | null)[]>;
|
|
40
|
+
/**
|
|
41
|
+
* @see https://redis.io/commands/json.arrlen
|
|
42
|
+
*/
|
|
43
|
+
arrlen: (key: string, path?: string | undefined) => Promise<(number | null)[]>;
|
|
44
|
+
/**
|
|
45
|
+
* @see https://redis.io/commands/json.arrpop
|
|
46
|
+
*/
|
|
47
|
+
arrpop: (key: string, path?: string | undefined, index?: number | undefined) => Promise<unknown[]>;
|
|
48
|
+
/**
|
|
49
|
+
* @see https://redis.io/commands/json.arrtrim
|
|
50
|
+
*/
|
|
51
|
+
arrtrim: (key: string, path?: string | undefined, start?: number | undefined, stop?: number | undefined) => Promise<(number | null)[]>;
|
|
52
|
+
/**
|
|
53
|
+
* @see https://redis.io/commands/json.clear
|
|
54
|
+
*/
|
|
55
|
+
clear: (key: string, path?: string | undefined) => Promise<number>;
|
|
56
|
+
/**
|
|
57
|
+
* @see https://redis.io/commands/json.del
|
|
58
|
+
*/
|
|
59
|
+
del: (key: string, path?: string | undefined) => Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* @see https://redis.io/commands/json.forget
|
|
62
|
+
*/
|
|
63
|
+
forget: (key: string, path?: string | undefined) => Promise<number>;
|
|
64
|
+
/**
|
|
65
|
+
* @see https://redis.io/commands/json.get
|
|
66
|
+
*/
|
|
67
|
+
get: (...args: CommandArgs<typeof JsonGetCommand>) => Promise<any>;
|
|
68
|
+
/**
|
|
69
|
+
* @see https://redis.io/commands/json.mget
|
|
70
|
+
*/
|
|
71
|
+
mget: (keys: string[], path: string) => Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* @see https://redis.io/commands/json.numincrby
|
|
74
|
+
*/
|
|
75
|
+
numincrby: (key: string, path: string, value: number) => Promise<(number | null)[]>;
|
|
76
|
+
/**
|
|
77
|
+
* @see https://redis.io/commands/json.nummultby
|
|
78
|
+
*/
|
|
79
|
+
nummultby: (key: string, path: string, value: number) => Promise<(number | null)[]>;
|
|
80
|
+
/**
|
|
81
|
+
* @see https://redis.io/commands/json.objkeys
|
|
82
|
+
*/
|
|
83
|
+
objkeys: (key: string, path?: string | undefined) => Promise<(string[] | null)[]>;
|
|
84
|
+
/**
|
|
85
|
+
* @see https://redis.io/commands/json.objlen
|
|
86
|
+
*/
|
|
87
|
+
objlen: (key: string, path?: string | undefined) => Promise<(number | null)[]>;
|
|
88
|
+
/**
|
|
89
|
+
* @see https://redis.io/commands/json.resp
|
|
90
|
+
*/
|
|
91
|
+
resp: (key: string, path?: string | undefined) => Promise<any>;
|
|
92
|
+
/**
|
|
93
|
+
* @see https://redis.io/commands/json.set
|
|
94
|
+
*/
|
|
95
|
+
set: (key: string, path: string, value: string | number | boolean | Record<string, unknown> | (string | number | boolean | Record<string, unknown>)[], opts?: {
|
|
96
|
+
nx: true;
|
|
97
|
+
xx?: undefined;
|
|
98
|
+
} | {
|
|
99
|
+
nx?: undefined;
|
|
100
|
+
xx: true;
|
|
101
|
+
} | undefined) => Promise<"OK" | null>;
|
|
102
|
+
/**
|
|
103
|
+
* @see https://redis.io/commands/json.strappend
|
|
104
|
+
*/
|
|
105
|
+
strappend: (key: string, path: string, value: string) => Promise<(number | null)[]>;
|
|
106
|
+
/**
|
|
107
|
+
* @see https://redis.io/commands/json.strlen
|
|
108
|
+
*/
|
|
109
|
+
strlen: (key: string, path?: string | undefined) => Promise<(number | null)[]>;
|
|
110
|
+
/**
|
|
111
|
+
* @see https://redis.io/commands/json.toggle
|
|
112
|
+
*/
|
|
113
|
+
toggle: (key: string, path: string) => Promise<number[]>;
|
|
114
|
+
/**
|
|
115
|
+
* @see https://redis.io/commands/json.type
|
|
116
|
+
*/
|
|
117
|
+
type: (key: string, path?: string | undefined) => Promise<string[]>;
|
|
118
|
+
};
|
|
31
119
|
/**
|
|
32
120
|
* Wrap a new middleware around the HTTP client.
|
|
33
121
|
*/
|
|
34
122
|
use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Technically this is not private, we can hide it from intellisense by doing this
|
|
125
|
+
*/
|
|
126
|
+
protected addTelemetry: (telemetry: Telemetry) => void;
|
|
127
|
+
createScript(script: string): Script;
|
|
35
128
|
/**
|
|
36
129
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
37
130
|
*
|
|
38
131
|
* @see {@link Pipeline}
|
|
39
132
|
*/
|
|
40
133
|
pipeline: () => Pipeline;
|
|
134
|
+
/**
|
|
135
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
136
|
+
*
|
|
137
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
138
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
139
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link Pipeline}
|
|
142
|
+
*/
|
|
143
|
+
multi: () => Pipeline;
|
|
41
144
|
/**
|
|
42
145
|
* @see https://redis.io/commands/append
|
|
43
146
|
*/
|
|
@@ -115,6 +218,10 @@ export declare class Redis {
|
|
|
115
218
|
* @see https://redis.io/commands/getbit
|
|
116
219
|
*/
|
|
117
220
|
getbit: (key: string, offset: number) => Promise<0 | 1>;
|
|
221
|
+
/**
|
|
222
|
+
* @see https://redis.io/commands/getdel
|
|
223
|
+
*/
|
|
224
|
+
getdel: <TData>(key: string) => Promise<TData | null>;
|
|
118
225
|
/**
|
|
119
226
|
* @see https://redis.io/commands/getrange
|
|
120
227
|
*/
|
|
@@ -165,6 +272,14 @@ export declare class Redis {
|
|
|
165
272
|
hmset: <TData>(key: string, kv: {
|
|
166
273
|
[field: string]: TData;
|
|
167
274
|
}) => Promise<"OK">;
|
|
275
|
+
/**
|
|
276
|
+
* @see https://redis.io/commands/hrandfield
|
|
277
|
+
*/
|
|
278
|
+
hrandfield: {
|
|
279
|
+
(key: string): Promise<string>;
|
|
280
|
+
(key: string, count: number): Promise<string[]>;
|
|
281
|
+
<TData extends Record<string, unknown>>(key: string, count: number, withValues: boolean): Promise<Partial<TData>>;
|
|
282
|
+
};
|
|
168
283
|
/**
|
|
169
284
|
* @see https://redis.io/commands/hscan
|
|
170
285
|
*/
|
|
@@ -215,6 +330,10 @@ export declare class Redis {
|
|
|
215
330
|
* @see https://redis.io/commands/llen
|
|
216
331
|
*/
|
|
217
332
|
llen: (key: string) => Promise<number>;
|
|
333
|
+
/**
|
|
334
|
+
* @see https://redis.io/commands/lmove
|
|
335
|
+
*/
|
|
336
|
+
lmove: <TData = string>(source: string, destination: string, whereFrom: "left" | "right", whereTo: "left" | "right") => Promise<TData>;
|
|
218
337
|
/**
|
|
219
338
|
* @see https://redis.io/commands/lpop
|
|
220
339
|
*/
|
|
@@ -254,7 +373,7 @@ export declare class Redis {
|
|
|
254
373
|
/**
|
|
255
374
|
* @see https://redis.io/commands/mget
|
|
256
375
|
*/
|
|
257
|
-
mget: <TData extends unknown[]>(
|
|
376
|
+
mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => Promise<TData>;
|
|
258
377
|
/**
|
|
259
378
|
* @see https://redis.io/commands/mset
|
|
260
379
|
*/
|
|
@@ -354,7 +473,7 @@ export declare class Redis {
|
|
|
354
473
|
/**
|
|
355
474
|
* @see https://redis.io/commands/set
|
|
356
475
|
*/
|
|
357
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
476
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
|
|
358
477
|
/**
|
|
359
478
|
* @see https://redis.io/commands/setbit
|
|
360
479
|
*/
|
|
@@ -383,10 +502,14 @@ export declare class Redis {
|
|
|
383
502
|
* @see https://redis.io/commands/sismember
|
|
384
503
|
*/
|
|
385
504
|
sismember: <TData>(key: string, member: TData) => Promise<0 | 1>;
|
|
505
|
+
/**
|
|
506
|
+
* @see https://redis.io/commands/smismember
|
|
507
|
+
*/
|
|
508
|
+
smismember: <TMembers extends unknown[]>(key: string, members: TMembers) => Promise<(0 | 1)[]>;
|
|
386
509
|
/**
|
|
387
510
|
* @see https://redis.io/commands/smembers
|
|
388
511
|
*/
|
|
389
|
-
smembers: (key: string) => Promise<
|
|
512
|
+
smembers: <TData extends unknown[] = string[]>(key: string) => Promise<TData>;
|
|
390
513
|
/**
|
|
391
514
|
* @see https://redis.io/commands/smove
|
|
392
515
|
*/
|
|
@@ -451,6 +574,10 @@ export declare class Redis {
|
|
|
451
574
|
* @see https://redis.io/commands/zcount
|
|
452
575
|
*/
|
|
453
576
|
zcount: (key: string, min: string | number, max: string | number) => Promise<number>;
|
|
577
|
+
/**
|
|
578
|
+
* @see https://redis.io/commands/zdiffstore
|
|
579
|
+
*/
|
|
580
|
+
zdiffstore: (destination: string, numkeys: number, ...keys: string[]) => Promise<number>;
|
|
454
581
|
/**
|
|
455
582
|
* @see https://redis.io/commands/zincrby
|
|
456
583
|
*/
|
|
@@ -463,6 +590,10 @@ export declare class Redis {
|
|
|
463
590
|
* @see https://redis.io/commands/zlexcount
|
|
464
591
|
*/
|
|
465
592
|
zlexcount: (key: string, min: string, max: string) => Promise<number>;
|
|
593
|
+
/**
|
|
594
|
+
* @see https://redis.io/commands/zmscore
|
|
595
|
+
*/
|
|
596
|
+
zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
|
|
466
597
|
/**
|
|
467
598
|
* @see https://redis.io/commands/zpopmax
|
|
468
599
|
*/
|
|
@@ -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
|
+
}
|
package/types/pkg/types.d.ts
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type CommandArgs<TCommand extends new (...args: any) => any> = ConstructorParameters<TCommand>[0];
|
|
2
|
+
export type Telemetry = {
|
|
3
|
+
/**
|
|
4
|
+
* Upstash-Telemetry-Sdk
|
|
5
|
+
* @example @upstash/redis@v1.1.1
|
|
6
|
+
*/
|
|
7
|
+
sdk?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Upstash-Telemetry-Platform
|
|
10
|
+
* @example cloudflare
|
|
11
|
+
*/
|
|
12
|
+
platform?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Upstash-Telemetry-Runtime
|
|
15
|
+
* @example node@v18
|
|
16
|
+
*/
|
|
17
|
+
runtime?: string;
|
|
18
|
+
};
|
|
19
|
+
export type RedisOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* Automatically try to deserialize the returned data from upstash using `JSON.deserialize`
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
automaticDeserialization?: boolean;
|
|
26
|
+
enableTelemetry?: boolean;
|
|
27
|
+
};
|
|
@@ -1,11 +1,15 @@
|
|
|
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";
|
|
4
|
+
type Env = {
|
|
5
|
+
UPSTASH_DISABLE_TELEMETRY?: string;
|
|
6
|
+
};
|
|
3
7
|
export type { Requester, UpstashRequest, UpstashResponse };
|
|
4
8
|
/**
|
|
5
9
|
* Connection credentials for upstash redis.
|
|
6
10
|
* Get them from https://console.upstash.com/redis/<uuid>
|
|
7
11
|
*/
|
|
8
|
-
export
|
|
12
|
+
export type RedisConfigCloudflare = {
|
|
9
13
|
/**
|
|
10
14
|
* UPSTASH_REDIS_REST_URL
|
|
11
15
|
*/
|
|
@@ -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,11 +1,11 @@
|
|
|
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.
|
|
6
6
|
* Get them from https://console.upstash.com/redis/<uuid>
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type RedisConfigFastly = {
|
|
9
9
|
/**
|
|
10
10
|
* UPSTASH_REDIS_REST_URL
|
|
11
11
|
*/
|
|
@@ -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,12 +1,12 @@
|
|
|
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
|
/**
|
|
6
6
|
* Connection credentials for upstash redis.
|
|
7
7
|
* Get them from https://console.upstash.com/redis/<uuid>
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type RedisConfigNodejs = {
|
|
10
10
|
/**
|
|
11
11
|
* UPSTASH_REDIS_REST_URL
|
|
12
12
|
*/
|
|
@@ -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
|
*/
|