@upstash/redis 0.0.0-ci.817cf518-20220823 → 0.0.0-ci.82657fb2-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/esm/deps/deno.land/std@0.82.0/encoding/base64.js +54 -0
- package/esm/deps/deno.land/std@0.82.0/encoding/utf8.js +13 -0
- package/esm/pkg/commands/getdel.js +9 -0
- package/esm/pkg/commands/mod.js +1 -0
- package/esm/pkg/commands/zmscore.js +10 -0
- package/esm/pkg/http.js +71 -3
- package/esm/pkg/pipeline.js +33 -6
- package/esm/pkg/redis.js +44 -2
- package/esm/platforms/nodejs.js +1 -1
- package/package.json +1 -1
- package/script/deps/deno.land/std@0.82.0/encoding/base64.js +59 -0
- package/script/deps/deno.land/std@0.82.0/encoding/utf8.js +18 -0
- package/script/pkg/commands/getdel.js +13 -0
- package/script/pkg/commands/mod.js +1 -0
- package/script/pkg/commands/zmscore.js +14 -0
- package/script/pkg/http.js +94 -3
- package/script/pkg/pipeline.js +32 -5
- package/script/pkg/redis.js +43 -1
- package/script/platforms/nodejs.js +1 -1
- package/types/deps/deno.land/std@0.82.0/encoding/base64.d.ts +11 -0
- package/types/deps/deno.land/std@0.82.0/encoding/utf8.d.ts +8 -0
- package/types/pkg/commands/getdel.d.ts +7 -0
- package/types/pkg/commands/mod.d.ts +1 -0
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/http.d.ts +2 -0
- package/types/pkg/pipeline.d.ts +15 -2
- package/types/pkg/redis.d.ts +18 -0
- package/types/platforms/nodejs.d.ts +1 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// deno-fmt-ignore
|
|
3
|
+
const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
|
|
4
|
+
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
|
|
5
|
+
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
|
|
6
|
+
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
|
|
7
|
+
"5", "6", "7", "8", "9", "+", "/"];
|
|
8
|
+
/**
|
|
9
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
10
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
11
|
+
* @param data
|
|
12
|
+
*/
|
|
13
|
+
export function encode(data) {
|
|
14
|
+
const uint8 = typeof data === "string"
|
|
15
|
+
? new TextEncoder().encode(data)
|
|
16
|
+
: data instanceof Uint8Array
|
|
17
|
+
? data
|
|
18
|
+
: new Uint8Array(data);
|
|
19
|
+
let result = "", i;
|
|
20
|
+
const l = uint8.length;
|
|
21
|
+
for (i = 2; i < l; i += 3) {
|
|
22
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
23
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
24
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
25
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
26
|
+
}
|
|
27
|
+
if (i === l + 1) {
|
|
28
|
+
// 1 octet yet to write
|
|
29
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
30
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
31
|
+
result += "==";
|
|
32
|
+
}
|
|
33
|
+
if (i === l) {
|
|
34
|
+
// 2 octets yet to write
|
|
35
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
36
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
37
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
38
|
+
result += "=";
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
44
|
+
* @param b64
|
|
45
|
+
*/
|
|
46
|
+
export function decode(b64) {
|
|
47
|
+
const binString = atob(b64);
|
|
48
|
+
const size = binString.length;
|
|
49
|
+
const bytes = new Uint8Array(size);
|
|
50
|
+
for (let i = 0; i < size; i++) {
|
|
51
|
+
bytes[i] = binString.charCodeAt(i);
|
|
52
|
+
}
|
|
53
|
+
return bytes;
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
/** A default TextEncoder instance */
|
|
3
|
+
export const encoder = new TextEncoder();
|
|
4
|
+
/** Shorthand for new TextEncoder().encode() */
|
|
5
|
+
export function encode(input) {
|
|
6
|
+
return encoder.encode(input);
|
|
7
|
+
}
|
|
8
|
+
/** A default TextDecoder instance */
|
|
9
|
+
export const decoder = new TextDecoder();
|
|
10
|
+
/** Shorthand for new TextDecoder().decode() */
|
|
11
|
+
export function decode(input) {
|
|
12
|
+
return decoder.decode(input);
|
|
13
|
+
}
|
package/esm/pkg/commands/mod.js
CHANGED
package/esm/pkg/http.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { UpstashError } from "./error.js";
|
|
2
|
+
import * as utf8 from "../deps/deno.land/std@0.82.0/encoding/utf8.js";
|
|
3
|
+
import * as base64 from "../deps/deno.land/std@0.82.0/encoding/base64.js";
|
|
2
4
|
export class HttpClient {
|
|
3
5
|
constructor(config) {
|
|
4
6
|
Object.defineProperty(this, "baseUrl", {
|
|
@@ -26,8 +28,12 @@ export class HttpClient {
|
|
|
26
28
|
value: void 0
|
|
27
29
|
});
|
|
28
30
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
29
|
-
this.headers = {
|
|
30
|
-
|
|
31
|
+
this.headers = {
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
"Upstash-Encoding": "base64",
|
|
34
|
+
...config.headers,
|
|
35
|
+
};
|
|
36
|
+
this.options = { backend: config.options?.backend, agent: config.agent };
|
|
31
37
|
if (typeof config?.retry === "boolean" && config?.retry === false) {
|
|
32
38
|
this.retry = {
|
|
33
39
|
attempts: 1,
|
|
@@ -48,6 +54,7 @@ export class HttpClient {
|
|
|
48
54
|
headers: this.headers,
|
|
49
55
|
body: JSON.stringify(req.body),
|
|
50
56
|
keepalive: true,
|
|
57
|
+
agent: this.options?.agent,
|
|
51
58
|
/**
|
|
52
59
|
* Fastly specific
|
|
53
60
|
*/
|
|
@@ -72,6 +79,67 @@ export class HttpClient {
|
|
|
72
79
|
if (!res.ok) {
|
|
73
80
|
throw new UpstashError(body.error);
|
|
74
81
|
}
|
|
75
|
-
|
|
82
|
+
console.time("decode");
|
|
83
|
+
const resp = Array.isArray(body) ? body.map(decode) : decode(body);
|
|
84
|
+
console.timeEnd("decode");
|
|
85
|
+
return resp;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function base64decode(b64) {
|
|
89
|
+
let dec = "";
|
|
90
|
+
try {
|
|
91
|
+
console.time("atob");
|
|
92
|
+
/**
|
|
93
|
+
* THIS WORKS
|
|
94
|
+
*/
|
|
95
|
+
const s = utf8.decode(base64.decode(b64));
|
|
96
|
+
console.timeEnd("atob");
|
|
97
|
+
console.time("escape");
|
|
98
|
+
console.timeEnd("escape");
|
|
99
|
+
dec = decodeURIComponent(s);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
|
|
103
|
+
return dec;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return decodeURIComponent(dec);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
|
|
110
|
+
return dec;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function decode(raw) {
|
|
114
|
+
let result = undefined;
|
|
115
|
+
switch (typeof raw.result) {
|
|
116
|
+
case "undefined":
|
|
117
|
+
return raw;
|
|
118
|
+
case "number": {
|
|
119
|
+
result = raw.result;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "object": {
|
|
123
|
+
if (Array.isArray(raw.result)) {
|
|
124
|
+
result = raw.result.map((v) => typeof v === "string"
|
|
125
|
+
? base64decode(v)
|
|
126
|
+
: Array.isArray(v)
|
|
127
|
+
? v.map(base64decode)
|
|
128
|
+
: v);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// If it's not an array it must be null
|
|
132
|
+
// Apparently null is an object in javascript
|
|
133
|
+
result = null;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "string": {
|
|
138
|
+
result = raw.result === "OK" ? "OK" : base64decode(raw.result);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
default:
|
|
142
|
+
break;
|
|
76
143
|
}
|
|
144
|
+
return { result, error: raw.error };
|
|
77
145
|
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
1
|
+
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { UpstashError } from "./error.js";
|
|
3
|
+
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
3
4
|
/**
|
|
4
5
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
5
6
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -16,7 +17,7 @@ import { UpstashError } from "./error.js";
|
|
|
16
17
|
* **Examples:**
|
|
17
18
|
*
|
|
18
19
|
* ```ts
|
|
19
|
-
* const p = redis.pipeline()
|
|
20
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
20
21
|
* p.set("key","value")
|
|
21
22
|
* p.get("key")
|
|
22
23
|
* const res = await p.exec()
|
|
@@ -39,7 +40,7 @@ import { UpstashError } from "./error.js";
|
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
42
|
export class Pipeline {
|
|
42
|
-
constructor(
|
|
43
|
+
constructor(opts) {
|
|
43
44
|
Object.defineProperty(this, "client", {
|
|
44
45
|
enumerable: true,
|
|
45
46
|
configurable: true,
|
|
@@ -58,6 +59,12 @@ export class Pipeline {
|
|
|
58
59
|
writable: true,
|
|
59
60
|
value: void 0
|
|
60
61
|
});
|
|
62
|
+
Object.defineProperty(this, "multiExec", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
61
68
|
/**
|
|
62
69
|
* Send the pipeline request to upstash.
|
|
63
70
|
*
|
|
@@ -76,8 +83,9 @@ export class Pipeline {
|
|
|
76
83
|
if (this.commands.length === 0) {
|
|
77
84
|
throw new Error("Pipeline is empty");
|
|
78
85
|
}
|
|
86
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
79
87
|
const res = (await this.client.request({
|
|
80
|
-
path
|
|
88
|
+
path,
|
|
81
89
|
body: Object.values(this.commands).map((c) => c.command),
|
|
82
90
|
}));
|
|
83
91
|
return res.map(({ error, result }, i) => {
|
|
@@ -250,6 +258,15 @@ export class Pipeline {
|
|
|
250
258
|
writable: true,
|
|
251
259
|
value: (...args) => this.chain(new GetBitCommand(args, this.commandOptions))
|
|
252
260
|
});
|
|
261
|
+
/**
|
|
262
|
+
* @see https://redis.io/commands/getdel
|
|
263
|
+
*/
|
|
264
|
+
Object.defineProperty(this, "getdel", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true,
|
|
268
|
+
value: (...args) => this.chain(new GetDelCommand(args, this.commandOptions))
|
|
269
|
+
});
|
|
253
270
|
/**
|
|
254
271
|
* @see https://redis.io/commands/getrange
|
|
255
272
|
*/
|
|
@@ -1011,6 +1028,15 @@ export class Pipeline {
|
|
|
1011
1028
|
writable: true,
|
|
1012
1029
|
value: (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions))
|
|
1013
1030
|
});
|
|
1031
|
+
/**
|
|
1032
|
+
* @see https://redis.io/commands/zmscore
|
|
1033
|
+
*/
|
|
1034
|
+
Object.defineProperty(this, "zmscore", {
|
|
1035
|
+
enumerable: true,
|
|
1036
|
+
configurable: true,
|
|
1037
|
+
writable: true,
|
|
1038
|
+
value: (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions))
|
|
1039
|
+
});
|
|
1014
1040
|
/**
|
|
1015
1041
|
* @see https://redis.io/commands/zpopmax
|
|
1016
1042
|
*/
|
|
@@ -1119,9 +1145,10 @@ export class Pipeline {
|
|
|
1119
1145
|
writable: true,
|
|
1120
1146
|
value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
|
|
1121
1147
|
});
|
|
1122
|
-
this.client = client;
|
|
1148
|
+
this.client = opts.client;
|
|
1123
1149
|
this.commands = [];
|
|
1124
|
-
this.commandOptions = commandOptions;
|
|
1150
|
+
this.commandOptions = opts.commandOptions;
|
|
1151
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1125
1152
|
}
|
|
1126
1153
|
/**
|
|
1127
1154
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/esm/pkg/redis.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
1
|
+
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { Pipeline } from "./pipeline.js";
|
|
3
3
|
import { Script } from "./script.js";
|
|
4
|
+
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
4
5
|
/**
|
|
5
6
|
* Serverless redis client for upstash.
|
|
6
7
|
*/
|
|
@@ -50,7 +51,30 @@ export class Redis {
|
|
|
50
51
|
enumerable: true,
|
|
51
52
|
configurable: true,
|
|
52
53
|
writable: true,
|
|
53
|
-
value: () => new Pipeline(
|
|
54
|
+
value: () => new Pipeline({
|
|
55
|
+
client: this.client,
|
|
56
|
+
commandOptions: this.opts,
|
|
57
|
+
multiExec: false,
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
62
|
+
*
|
|
63
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
64
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
65
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link Pipeline}
|
|
68
|
+
*/
|
|
69
|
+
Object.defineProperty(this, "multi", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: () => new Pipeline({
|
|
74
|
+
client: this.client,
|
|
75
|
+
commandOptions: this.opts,
|
|
76
|
+
multiExec: true,
|
|
77
|
+
})
|
|
54
78
|
});
|
|
55
79
|
/**
|
|
56
80
|
* @see https://redis.io/commands/append
|
|
@@ -214,6 +238,15 @@ export class Redis {
|
|
|
214
238
|
writable: true,
|
|
215
239
|
value: (...args) => new GetBitCommand(args, this.opts).exec(this.client)
|
|
216
240
|
});
|
|
241
|
+
/**
|
|
242
|
+
* @see https://redis.io/commands/getdel
|
|
243
|
+
*/
|
|
244
|
+
Object.defineProperty(this, "getdel", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
configurable: true,
|
|
247
|
+
writable: true,
|
|
248
|
+
value: (...args) => new GetDelCommand(args, this.opts).exec(this.client)
|
|
249
|
+
});
|
|
217
250
|
/**
|
|
218
251
|
* @see https://redis.io/commands/getrange
|
|
219
252
|
*/
|
|
@@ -975,6 +1008,15 @@ export class Redis {
|
|
|
975
1008
|
writable: true,
|
|
976
1009
|
value: (...args) => new ZLexCountCommand(args, this.opts).exec(this.client)
|
|
977
1010
|
});
|
|
1011
|
+
/**
|
|
1012
|
+
* @see https://redis.io/commands/zmscore
|
|
1013
|
+
*/
|
|
1014
|
+
Object.defineProperty(this, "zmscore", {
|
|
1015
|
+
enumerable: true,
|
|
1016
|
+
configurable: true,
|
|
1017
|
+
writable: true,
|
|
1018
|
+
value: (...args) => new ZMScoreCommand(args, this.opts).exec(this.client)
|
|
1019
|
+
});
|
|
978
1020
|
/**
|
|
979
1021
|
* @see https://redis.io/commands/zpopmax
|
|
980
1022
|
*/
|
package/esm/platforms/nodejs.js
CHANGED
|
@@ -24,7 +24,7 @@ export class Redis extends core.Redis {
|
|
|
24
24
|
baseUrl: configOrRequester.url,
|
|
25
25
|
retry: configOrRequester.retry,
|
|
26
26
|
headers: { authorization: `Bearer ${configOrRequester.token}` },
|
|
27
|
-
|
|
27
|
+
agent: configOrRequester.agent,
|
|
28
28
|
});
|
|
29
29
|
super(client, {
|
|
30
30
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "./script/platforms/nodejs.js",
|
|
4
4
|
"types": "./types/platforms/nodejs.d.ts",
|
|
5
5
|
"name": "@upstash/redis",
|
|
6
|
-
"version": "v0.0.0-ci.
|
|
6
|
+
"version": "v0.0.0-ci.82657fb2-20221116",
|
|
7
7
|
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.decode = exports.encode = void 0;
|
|
5
|
+
// deno-fmt-ignore
|
|
6
|
+
const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
|
|
7
|
+
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
|
|
8
|
+
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
|
|
9
|
+
"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
|
|
10
|
+
"5", "6", "7", "8", "9", "+", "/"];
|
|
11
|
+
/**
|
|
12
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
13
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
14
|
+
* @param data
|
|
15
|
+
*/
|
|
16
|
+
function encode(data) {
|
|
17
|
+
const uint8 = typeof data === "string"
|
|
18
|
+
? new TextEncoder().encode(data)
|
|
19
|
+
: data instanceof Uint8Array
|
|
20
|
+
? data
|
|
21
|
+
: new Uint8Array(data);
|
|
22
|
+
let result = "", i;
|
|
23
|
+
const l = uint8.length;
|
|
24
|
+
for (i = 2; i < l; i += 3) {
|
|
25
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
26
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
27
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
28
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
29
|
+
}
|
|
30
|
+
if (i === l + 1) {
|
|
31
|
+
// 1 octet yet to write
|
|
32
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
33
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
34
|
+
result += "==";
|
|
35
|
+
}
|
|
36
|
+
if (i === l) {
|
|
37
|
+
// 2 octets yet to write
|
|
38
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
39
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
40
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
41
|
+
result += "=";
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
exports.encode = encode;
|
|
46
|
+
/**
|
|
47
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
48
|
+
* @param b64
|
|
49
|
+
*/
|
|
50
|
+
function decode(b64) {
|
|
51
|
+
const binString = atob(b64);
|
|
52
|
+
const size = binString.length;
|
|
53
|
+
const bytes = new Uint8Array(size);
|
|
54
|
+
for (let i = 0; i < size; i++) {
|
|
55
|
+
bytes[i] = binString.charCodeAt(i);
|
|
56
|
+
}
|
|
57
|
+
return bytes;
|
|
58
|
+
}
|
|
59
|
+
exports.decode = decode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.decode = exports.decoder = exports.encode = exports.encoder = void 0;
|
|
5
|
+
/** A default TextEncoder instance */
|
|
6
|
+
exports.encoder = new TextEncoder();
|
|
7
|
+
/** Shorthand for new TextEncoder().encode() */
|
|
8
|
+
function encode(input) {
|
|
9
|
+
return exports.encoder.encode(input);
|
|
10
|
+
}
|
|
11
|
+
exports.encode = encode;
|
|
12
|
+
/** A default TextDecoder instance */
|
|
13
|
+
exports.decoder = new TextDecoder();
|
|
14
|
+
/** Shorthand for new TextDecoder().decode() */
|
|
15
|
+
function decode(input) {
|
|
16
|
+
return exports.decoder.decode(input);
|
|
17
|
+
}
|
|
18
|
+
exports.decode = decode;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetDelCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/getdel
|
|
7
|
+
*/
|
|
8
|
+
class GetDelCommand extends command_js_1.Command {
|
|
9
|
+
constructor(cmd, opts) {
|
|
10
|
+
super(["getdel", ...cmd], opts);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.GetDelCommand = GetDelCommand;
|
|
@@ -35,6 +35,7 @@ __exportStar(require("./get.js"), exports);
|
|
|
35
35
|
__exportStar(require("./getbit.js"), exports);
|
|
36
36
|
__exportStar(require("./getrange.js"), exports);
|
|
37
37
|
__exportStar(require("./getset.js"), exports);
|
|
38
|
+
__exportStar(require("./getdel.js"), exports);
|
|
38
39
|
__exportStar(require("./hdel.js"), exports);
|
|
39
40
|
__exportStar(require("./hexists.js"), exports);
|
|
40
41
|
__exportStar(require("./hget.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZMScoreCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/zmscore
|
|
7
|
+
*/
|
|
8
|
+
class ZMScoreCommand extends command_js_1.Command {
|
|
9
|
+
constructor(cmd, opts) {
|
|
10
|
+
const [key, members] = cmd;
|
|
11
|
+
super(["zmscore", key, ...members], opts);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ZMScoreCommand = ZMScoreCommand;
|
package/script/pkg/http.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.HttpClient = void 0;
|
|
4
27
|
const error_js_1 = require("./error.js");
|
|
28
|
+
const utf8 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/utf8.js"));
|
|
29
|
+
const base64 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/base64.js"));
|
|
5
30
|
class HttpClient {
|
|
6
31
|
constructor(config) {
|
|
7
32
|
Object.defineProperty(this, "baseUrl", {
|
|
@@ -29,8 +54,12 @@ class HttpClient {
|
|
|
29
54
|
value: void 0
|
|
30
55
|
});
|
|
31
56
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
32
|
-
this.headers = {
|
|
33
|
-
|
|
57
|
+
this.headers = {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
"Upstash-Encoding": "base64",
|
|
60
|
+
...config.headers,
|
|
61
|
+
};
|
|
62
|
+
this.options = { backend: config.options?.backend, agent: config.agent };
|
|
34
63
|
if (typeof config?.retry === "boolean" && config?.retry === false) {
|
|
35
64
|
this.retry = {
|
|
36
65
|
attempts: 1,
|
|
@@ -51,6 +80,7 @@ class HttpClient {
|
|
|
51
80
|
headers: this.headers,
|
|
52
81
|
body: JSON.stringify(req.body),
|
|
53
82
|
keepalive: true,
|
|
83
|
+
agent: this.options?.agent,
|
|
54
84
|
/**
|
|
55
85
|
* Fastly specific
|
|
56
86
|
*/
|
|
@@ -75,7 +105,68 @@ class HttpClient {
|
|
|
75
105
|
if (!res.ok) {
|
|
76
106
|
throw new error_js_1.UpstashError(body.error);
|
|
77
107
|
}
|
|
78
|
-
|
|
108
|
+
console.time("decode");
|
|
109
|
+
const resp = Array.isArray(body) ? body.map(decode) : decode(body);
|
|
110
|
+
console.timeEnd("decode");
|
|
111
|
+
return resp;
|
|
79
112
|
}
|
|
80
113
|
}
|
|
81
114
|
exports.HttpClient = HttpClient;
|
|
115
|
+
function base64decode(b64) {
|
|
116
|
+
let dec = "";
|
|
117
|
+
try {
|
|
118
|
+
console.time("atob");
|
|
119
|
+
/**
|
|
120
|
+
* THIS WORKS
|
|
121
|
+
*/
|
|
122
|
+
const s = utf8.decode(base64.decode(b64));
|
|
123
|
+
console.timeEnd("atob");
|
|
124
|
+
console.time("escape");
|
|
125
|
+
console.timeEnd("escape");
|
|
126
|
+
dec = decodeURIComponent(s);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
|
|
130
|
+
return dec;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return decodeURIComponent(dec);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
|
|
137
|
+
return dec;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function decode(raw) {
|
|
141
|
+
let result = undefined;
|
|
142
|
+
switch (typeof raw.result) {
|
|
143
|
+
case "undefined":
|
|
144
|
+
return raw;
|
|
145
|
+
case "number": {
|
|
146
|
+
result = raw.result;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "object": {
|
|
150
|
+
if (Array.isArray(raw.result)) {
|
|
151
|
+
result = raw.result.map((v) => typeof v === "string"
|
|
152
|
+
? base64decode(v)
|
|
153
|
+
: Array.isArray(v)
|
|
154
|
+
? v.map(base64decode)
|
|
155
|
+
: v);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// If it's not an array it must be null
|
|
159
|
+
// Apparently null is an object in javascript
|
|
160
|
+
result = null;
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "string": {
|
|
165
|
+
result = raw.result === "OK" ? "OK" : base64decode(raw.result);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
return { result, error: raw.error };
|
|
172
|
+
}
|
package/script/pkg/pipeline.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Pipeline = void 0;
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const error_js_1 = require("./error.js");
|
|
6
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
6
7
|
/**
|
|
7
8
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
8
9
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -19,7 +20,7 @@ const error_js_1 = require("./error.js");
|
|
|
19
20
|
* **Examples:**
|
|
20
21
|
*
|
|
21
22
|
* ```ts
|
|
22
|
-
* const p = redis.pipeline()
|
|
23
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
23
24
|
* p.set("key","value")
|
|
24
25
|
* p.get("key")
|
|
25
26
|
* const res = await p.exec()
|
|
@@ -42,7 +43,7 @@ const error_js_1 = require("./error.js");
|
|
|
42
43
|
* ```
|
|
43
44
|
*/
|
|
44
45
|
class Pipeline {
|
|
45
|
-
constructor(
|
|
46
|
+
constructor(opts) {
|
|
46
47
|
Object.defineProperty(this, "client", {
|
|
47
48
|
enumerable: true,
|
|
48
49
|
configurable: true,
|
|
@@ -61,6 +62,12 @@ class Pipeline {
|
|
|
61
62
|
writable: true,
|
|
62
63
|
value: void 0
|
|
63
64
|
});
|
|
65
|
+
Object.defineProperty(this, "multiExec", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
64
71
|
/**
|
|
65
72
|
* Send the pipeline request to upstash.
|
|
66
73
|
*
|
|
@@ -79,8 +86,9 @@ class Pipeline {
|
|
|
79
86
|
if (this.commands.length === 0) {
|
|
80
87
|
throw new Error("Pipeline is empty");
|
|
81
88
|
}
|
|
89
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
82
90
|
const res = (await this.client.request({
|
|
83
|
-
path
|
|
91
|
+
path,
|
|
84
92
|
body: Object.values(this.commands).map((c) => c.command),
|
|
85
93
|
}));
|
|
86
94
|
return res.map(({ error, result }, i) => {
|
|
@@ -253,6 +261,15 @@ class Pipeline {
|
|
|
253
261
|
writable: true,
|
|
254
262
|
value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
|
|
255
263
|
});
|
|
264
|
+
/**
|
|
265
|
+
* @see https://redis.io/commands/getdel
|
|
266
|
+
*/
|
|
267
|
+
Object.defineProperty(this, "getdel", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
configurable: true,
|
|
270
|
+
writable: true,
|
|
271
|
+
value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
|
|
272
|
+
});
|
|
256
273
|
/**
|
|
257
274
|
* @see https://redis.io/commands/getrange
|
|
258
275
|
*/
|
|
@@ -1014,6 +1031,15 @@ class Pipeline {
|
|
|
1014
1031
|
writable: true,
|
|
1015
1032
|
value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
|
|
1016
1033
|
});
|
|
1034
|
+
/**
|
|
1035
|
+
* @see https://redis.io/commands/zmscore
|
|
1036
|
+
*/
|
|
1037
|
+
Object.defineProperty(this, "zmscore", {
|
|
1038
|
+
enumerable: true,
|
|
1039
|
+
configurable: true,
|
|
1040
|
+
writable: true,
|
|
1041
|
+
value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
|
|
1042
|
+
});
|
|
1017
1043
|
/**
|
|
1018
1044
|
* @see https://redis.io/commands/zpopmax
|
|
1019
1045
|
*/
|
|
@@ -1122,9 +1148,10 @@ class Pipeline {
|
|
|
1122
1148
|
writable: true,
|
|
1123
1149
|
value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
|
|
1124
1150
|
});
|
|
1125
|
-
this.client = client;
|
|
1151
|
+
this.client = opts.client;
|
|
1126
1152
|
this.commands = [];
|
|
1127
|
-
this.commandOptions = commandOptions;
|
|
1153
|
+
this.commandOptions = opts.commandOptions;
|
|
1154
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1128
1155
|
}
|
|
1129
1156
|
/**
|
|
1130
1157
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/script/pkg/redis.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Redis = void 0;
|
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const pipeline_js_1 = require("./pipeline.js");
|
|
6
6
|
const script_js_1 = require("./script.js");
|
|
7
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
7
8
|
/**
|
|
8
9
|
* Serverless redis client for upstash.
|
|
9
10
|
*/
|
|
@@ -53,7 +54,30 @@ class Redis {
|
|
|
53
54
|
enumerable: true,
|
|
54
55
|
configurable: true,
|
|
55
56
|
writable: true,
|
|
56
|
-
value: () => new pipeline_js_1.Pipeline(
|
|
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
|
+
})
|
|
57
81
|
});
|
|
58
82
|
/**
|
|
59
83
|
* @see https://redis.io/commands/append
|
|
@@ -217,6 +241,15 @@ class Redis {
|
|
|
217
241
|
writable: true,
|
|
218
242
|
value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
|
|
219
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
|
+
});
|
|
220
253
|
/**
|
|
221
254
|
* @see https://redis.io/commands/getrange
|
|
222
255
|
*/
|
|
@@ -978,6 +1011,15 @@ class Redis {
|
|
|
978
1011
|
writable: true,
|
|
979
1012
|
value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
|
|
980
1013
|
});
|
|
1014
|
+
/**
|
|
1015
|
+
* @see https://redis.io/commands/zmscore
|
|
1016
|
+
*/
|
|
1017
|
+
Object.defineProperty(this, "zmscore", {
|
|
1018
|
+
enumerable: true,
|
|
1019
|
+
configurable: true,
|
|
1020
|
+
writable: true,
|
|
1021
|
+
value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
|
|
1022
|
+
});
|
|
981
1023
|
/**
|
|
982
1024
|
* @see https://redis.io/commands/zpopmax
|
|
983
1025
|
*/
|
|
@@ -50,7 +50,7 @@ class Redis extends core.Redis {
|
|
|
50
50
|
baseUrl: configOrRequester.url,
|
|
51
51
|
retry: configOrRequester.retry,
|
|
52
52
|
headers: { authorization: `Bearer ${configOrRequester.token}` },
|
|
53
|
-
|
|
53
|
+
agent: configOrRequester.agent,
|
|
54
54
|
});
|
|
55
55
|
super(client, {
|
|
56
56
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
3
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
4
|
+
* @param data
|
|
5
|
+
*/
|
|
6
|
+
export declare function encode(data: ArrayBuffer | string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
9
|
+
* @param b64
|
|
10
|
+
*/
|
|
11
|
+
export declare function decode(b64: string): Uint8Array;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A default TextEncoder instance */
|
|
2
|
+
export declare const encoder: any;
|
|
3
|
+
/** Shorthand for new TextEncoder().encode() */
|
|
4
|
+
export declare function encode(input?: string): Uint8Array;
|
|
5
|
+
/** A default TextDecoder instance */
|
|
6
|
+
export declare const decoder: any;
|
|
7
|
+
/** Shorthand for new TextDecoder().decode() */
|
|
8
|
+
export declare function decode(input?: Uint8Array): string;
|
|
@@ -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,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
|
+
}
|
package/types/pkg/http.d.ts
CHANGED
|
@@ -37,12 +37,14 @@ export declare type HttpClientConfig = {
|
|
|
37
37
|
baseUrl: string;
|
|
38
38
|
options?: Options;
|
|
39
39
|
retry?: RetryConfig;
|
|
40
|
+
agent?: any;
|
|
40
41
|
};
|
|
41
42
|
export declare class HttpClient implements Requester {
|
|
42
43
|
baseUrl: string;
|
|
43
44
|
headers: Record<string, string>;
|
|
44
45
|
readonly options?: {
|
|
45
46
|
backend?: string;
|
|
47
|
+
agent: any;
|
|
46
48
|
};
|
|
47
49
|
readonly retry: {
|
|
48
50
|
attempts: number;
|
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
|
*/
|
|
@@ -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
|
@@ -40,6 +40,16 @@ export declare class Redis {
|
|
|
40
40
|
* @see {@link Pipeline}
|
|
41
41
|
*/
|
|
42
42
|
pipeline: () => Pipeline;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
45
|
+
*
|
|
46
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
47
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
48
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link Pipeline}
|
|
51
|
+
*/
|
|
52
|
+
multi: () => Pipeline;
|
|
43
53
|
/**
|
|
44
54
|
* @see https://redis.io/commands/append
|
|
45
55
|
*/
|
|
@@ -117,6 +127,10 @@ export declare class Redis {
|
|
|
117
127
|
* @see https://redis.io/commands/getbit
|
|
118
128
|
*/
|
|
119
129
|
getbit: (key: string, offset: number) => Promise<0 | 1>;
|
|
130
|
+
/**
|
|
131
|
+
* @see https://redis.io/commands/getdel
|
|
132
|
+
*/
|
|
133
|
+
getdel: <TData>(key: string) => Promise<TData | null>;
|
|
120
134
|
/**
|
|
121
135
|
* @see https://redis.io/commands/getrange
|
|
122
136
|
*/
|
|
@@ -465,6 +479,10 @@ export declare class Redis {
|
|
|
465
479
|
* @see https://redis.io/commands/zlexcount
|
|
466
480
|
*/
|
|
467
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>;
|
|
468
486
|
/**
|
|
469
487
|
* @see https://redis.io/commands/zpopmax
|
|
470
488
|
*/
|