@upstash/redis 0.0.0-ci.b1e842dc-20220903 → 0.0.0-ci.b8efaf97-20230119
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 +19 -17
- 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/lmove.js +9 -0
- package/esm/pkg/commands/mod.js +4 -0
- package/esm/pkg/commands/smismember.js +9 -0
- package/esm/pkg/commands/zdiffstore.js +9 -0
- package/esm/pkg/commands/zmscore.js +1 -1
- package/esm/pkg/http.js +99 -2
- package/esm/pkg/pipeline.js +61 -6
- package/esm/pkg/redis.js +90 -2
- package/esm/platforms/cloudflare.js +10 -2
- package/esm/platforms/fastly.js +1 -0
- package/esm/platforms/node_with_fetch.js +27 -1
- package/esm/platforms/nodejs.js +22 -1
- package/esm/version.js +1 -0
- package/package.json +1 -1
- 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/lmove.js +13 -0
- package/script/pkg/commands/mod.js +4 -0
- package/script/pkg/commands/smismember.js +13 -0
- package/script/pkg/commands/zdiffstore.js +13 -0
- package/script/pkg/commands/zmscore.js +1 -1
- package/script/pkg/http.js +99 -2
- package/script/pkg/pipeline.js +60 -5
- package/script/pkg/redis.js +89 -1
- package/script/platforms/cloudflare.js +10 -2
- package/script/platforms/fastly.js +1 -0
- package/script/platforms/node_with_fetch.js +27 -1
- package/script/platforms/nodejs.js +22 -1
- package/script/version.js +4 -0
- package/types/pkg/commands/getdel.d.ts +7 -0
- package/types/pkg/commands/hrandfield.d.ts +9 -0
- package/types/pkg/commands/lmove.d.ts +12 -0
- package/types/pkg/commands/mod.d.ts +4 -0
- package/types/pkg/commands/smembers.d.ts +2 -2
- package/types/pkg/commands/smismember.d.ts +7 -0
- package/types/pkg/commands/zdiffstore.d.ts +7 -0
- package/types/pkg/commands/zmscore.d.ts +1 -1
- package/types/pkg/http.d.ts +38 -4
- package/types/pkg/pipeline.d.ts +28 -3
- package/types/pkg/redis.d.ts +39 -1
- package/types/pkg/types.d.ts +17 -0
- package/types/platforms/cloudflare.d.ts +8 -7
- 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/version.d.ts +1 -0
package/README.md
CHANGED
|
@@ -81,23 +81,12 @@ data = await redis.spop('animals', 1)
|
|
|
81
81
|
console.log(data)
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
## Troubleshooting
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
for
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { Redis } from "@upstash/redis/with-fetch";
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Upgrading from v0.2.0?
|
|
96
|
-
|
|
97
|
-
Please read the
|
|
98
|
-
[migration guide](https://docs.upstash.com/redis/sdks/javascriptsdk/migration).
|
|
99
|
-
For further explanation we wrote a
|
|
100
|
-
[blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
|
|
86
|
+
We have a
|
|
87
|
+
[dedicated page](https://docs.upstash.com/redis/sdks/javascriptsdk/troubleshooting)
|
|
88
|
+
for common problems. If you can't find a solution, please
|
|
89
|
+
[open an issue](https://github.com/upstash/upstash-redis/issues/new).
|
|
101
90
|
|
|
102
91
|
## Docs
|
|
103
92
|
|
|
@@ -119,5 +108,18 @@ the url and token
|
|
|
119
108
|
UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
|
|
120
109
|
```
|
|
121
110
|
|
|
122
|
-
|
|
111
|
+
### Telemetry
|
|
112
|
+
|
|
113
|
+
This library sends anonymous telemetry data to help us improve your experience.
|
|
114
|
+
We collect the following:
|
|
115
|
+
|
|
116
|
+
- SDK version
|
|
117
|
+
- Platform (Deno, Cloudflare, Vercel)
|
|
118
|
+
- Runtime version (node@18.x)
|
|
119
|
+
|
|
120
|
+
You can opt out by setting the `UPSTASH_DISABLE_TELEMETRY` environment variable
|
|
121
|
+
to any truthy value.
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
UPSTASH_DISABLE_TELEMETRY=1
|
|
123
125
|
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
function deserialize(result) {
|
|
3
|
+
if (result.length === 0) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const obj = {};
|
|
7
|
+
while (result.length >= 2) {
|
|
8
|
+
const key = result.shift();
|
|
9
|
+
const value = result.shift();
|
|
10
|
+
try {
|
|
11
|
+
obj[key] = JSON.parse(value);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
obj[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @see https://redis.io/commands/hrandfield
|
|
21
|
+
*/
|
|
22
|
+
export class HRandFieldCommand extends Command {
|
|
23
|
+
constructor(cmd, opts) {
|
|
24
|
+
const command = ["hrandfield", cmd[0]];
|
|
25
|
+
if (typeof cmd[1] === "number") {
|
|
26
|
+
command.push(cmd[1]);
|
|
27
|
+
}
|
|
28
|
+
if (cmd[2]) {
|
|
29
|
+
command.push("WITHVALUES");
|
|
30
|
+
}
|
|
31
|
+
super(command, {
|
|
32
|
+
// @ts-ignore TODO:
|
|
33
|
+
deserialize: cmd[2]
|
|
34
|
+
? (result) => deserialize(result)
|
|
35
|
+
: opts?.deserialize,
|
|
36
|
+
...opts,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
package/esm/pkg/commands/mod.js
CHANGED
|
@@ -17,11 +17,13 @@ export * from "./flushall.js";
|
|
|
17
17
|
export * from "./flushdb.js";
|
|
18
18
|
export * from "./get.js";
|
|
19
19
|
export * from "./getbit.js";
|
|
20
|
+
export * from "./getdel.js";
|
|
20
21
|
export * from "./getrange.js";
|
|
21
22
|
export * from "./getset.js";
|
|
22
23
|
export * from "./hdel.js";
|
|
23
24
|
export * from "./hexists.js";
|
|
24
25
|
export * from "./hget.js";
|
|
26
|
+
export * from "./smismember.js";
|
|
25
27
|
export * from "./hgetall.js";
|
|
26
28
|
export * from "./hincrby.js";
|
|
27
29
|
export * from "./hincrbyfloat.js";
|
|
@@ -29,6 +31,7 @@ export * from "./hkeys.js";
|
|
|
29
31
|
export * from "./hlen.js";
|
|
30
32
|
export * from "./hmget.js";
|
|
31
33
|
export * from "./hmset.js";
|
|
34
|
+
export * from "./hrandfield.js";
|
|
32
35
|
export * from "./hscan.js";
|
|
33
36
|
export * from "./hset.js";
|
|
34
37
|
export * from "./hsetnx.js";
|
|
@@ -41,6 +44,7 @@ export * from "./keys.js";
|
|
|
41
44
|
export * from "./lindex.js";
|
|
42
45
|
export * from "./linsert.js";
|
|
43
46
|
export * from "./llen.js";
|
|
47
|
+
export * from "./lmove.js";
|
|
44
48
|
export * from "./lpop.js";
|
|
45
49
|
export * from "./lpos.js";
|
|
46
50
|
export * from "./lpush.js";
|
package/esm/pkg/http.js
CHANGED
|
@@ -25,9 +25,28 @@ export class HttpClient {
|
|
|
25
25
|
writable: true,
|
|
26
26
|
value: void 0
|
|
27
27
|
});
|
|
28
|
+
this.options = {
|
|
29
|
+
backend: config.options?.backend,
|
|
30
|
+
agent: config.agent,
|
|
31
|
+
responseEncoding: config.responseEncoding ?? "base64", // default to base64
|
|
32
|
+
};
|
|
28
33
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
29
|
-
this.headers = {
|
|
30
|
-
|
|
34
|
+
this.headers = {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
...config.headers,
|
|
37
|
+
};
|
|
38
|
+
if (config.telemetry?.runtime) {
|
|
39
|
+
this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
|
|
40
|
+
}
|
|
41
|
+
if (config.telemetry?.platform) {
|
|
42
|
+
this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
|
|
43
|
+
}
|
|
44
|
+
if (config.telemetry?.sdk) {
|
|
45
|
+
this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
|
|
46
|
+
}
|
|
47
|
+
if (this.options.responseEncoding === "base64") {
|
|
48
|
+
this.headers["Upstash-Encoding"] = "base64";
|
|
49
|
+
}
|
|
31
50
|
if (typeof config?.retry === "boolean" && config?.retry === false) {
|
|
32
51
|
this.retry = {
|
|
33
52
|
attempts: 1,
|
|
@@ -42,12 +61,30 @@ export class HttpClient {
|
|
|
42
61
|
};
|
|
43
62
|
}
|
|
44
63
|
}
|
|
64
|
+
mergeTelemetry(telemetry) {
|
|
65
|
+
function merge(obj, key, value) {
|
|
66
|
+
if (!value) {
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
if (obj[key]) {
|
|
70
|
+
obj[key] = [obj[key], value].join(",");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime);
|
|
78
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform);
|
|
79
|
+
this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk);
|
|
80
|
+
}
|
|
45
81
|
async request(req) {
|
|
46
82
|
const requestOptions = {
|
|
47
83
|
method: "POST",
|
|
48
84
|
headers: this.headers,
|
|
49
85
|
body: JSON.stringify(req.body),
|
|
50
86
|
keepalive: true,
|
|
87
|
+
agent: this.options?.agent,
|
|
51
88
|
/**
|
|
52
89
|
* Fastly specific
|
|
53
90
|
*/
|
|
@@ -72,6 +109,66 @@ export class HttpClient {
|
|
|
72
109
|
if (!res.ok) {
|
|
73
110
|
throw new UpstashError(body.error);
|
|
74
111
|
}
|
|
112
|
+
if (this.options?.responseEncoding === "base64") {
|
|
113
|
+
return Array.isArray(body) ? body.map(decode) : decode(body);
|
|
114
|
+
}
|
|
75
115
|
return body;
|
|
76
116
|
}
|
|
77
117
|
}
|
|
118
|
+
function base64decode(b64) {
|
|
119
|
+
let dec = "";
|
|
120
|
+
try {
|
|
121
|
+
/**
|
|
122
|
+
* Using only atob() is not enough because it doesn't work with unicode characters
|
|
123
|
+
*/
|
|
124
|
+
const binString = atob(b64);
|
|
125
|
+
const size = binString.length;
|
|
126
|
+
const bytes = new Uint8Array(size);
|
|
127
|
+
for (let i = 0; i < size; i++) {
|
|
128
|
+
bytes[i] = binString.charCodeAt(i);
|
|
129
|
+
}
|
|
130
|
+
dec = new TextDecoder().decode(bytes);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
dec = b64;
|
|
134
|
+
}
|
|
135
|
+
return dec;
|
|
136
|
+
// try {
|
|
137
|
+
// return decodeURIComponent(dec);
|
|
138
|
+
// } catch {
|
|
139
|
+
// return dec;
|
|
140
|
+
// }
|
|
141
|
+
}
|
|
142
|
+
function decode(raw) {
|
|
143
|
+
let result = undefined;
|
|
144
|
+
switch (typeof raw.result) {
|
|
145
|
+
case "undefined":
|
|
146
|
+
return raw;
|
|
147
|
+
case "number": {
|
|
148
|
+
result = raw.result;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case "object": {
|
|
152
|
+
if (Array.isArray(raw.result)) {
|
|
153
|
+
result = raw.result.map((v) => typeof v === "string"
|
|
154
|
+
? base64decode(v)
|
|
155
|
+
: Array.isArray(v)
|
|
156
|
+
? v.map(base64decode)
|
|
157
|
+
: v);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// If it's not an array it must be null
|
|
161
|
+
// Apparently null is an object in javascript
|
|
162
|
+
result = null;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "string": {
|
|
167
|
+
result = raw.result === "OK" ? "OK" : base64decode(raw.result);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return { result, error: raw.error };
|
|
174
|
+
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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, LMoveCommand, 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, SMIsMemberCommand, 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
3
|
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
4
|
+
import { HRandFieldCommand } from "./commands/hrandfield.js";
|
|
5
|
+
import { ZDiffStoreCommand } from "./commands/zdiffstore.js";
|
|
4
6
|
/**
|
|
5
7
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
6
8
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -17,7 +19,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
|
17
19
|
* **Examples:**
|
|
18
20
|
*
|
|
19
21
|
* ```ts
|
|
20
|
-
* const p = redis.pipeline()
|
|
22
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
21
23
|
* p.set("key","value")
|
|
22
24
|
* p.get("key")
|
|
23
25
|
* const res = await p.exec()
|
|
@@ -40,7 +42,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
|
40
42
|
* ```
|
|
41
43
|
*/
|
|
42
44
|
export class Pipeline {
|
|
43
|
-
constructor(
|
|
45
|
+
constructor(opts) {
|
|
44
46
|
Object.defineProperty(this, "client", {
|
|
45
47
|
enumerable: true,
|
|
46
48
|
configurable: true,
|
|
@@ -59,6 +61,12 @@ export class Pipeline {
|
|
|
59
61
|
writable: true,
|
|
60
62
|
value: void 0
|
|
61
63
|
});
|
|
64
|
+
Object.defineProperty(this, "multiExec", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: void 0
|
|
69
|
+
});
|
|
62
70
|
/**
|
|
63
71
|
* Send the pipeline request to upstash.
|
|
64
72
|
*
|
|
@@ -77,8 +85,9 @@ export class Pipeline {
|
|
|
77
85
|
if (this.commands.length === 0) {
|
|
78
86
|
throw new Error("Pipeline is empty");
|
|
79
87
|
}
|
|
88
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
80
89
|
const res = (await this.client.request({
|
|
81
|
-
path
|
|
90
|
+
path,
|
|
82
91
|
body: Object.values(this.commands).map((c) => c.command),
|
|
83
92
|
}));
|
|
84
93
|
return res.map(({ error, result }, i) => {
|
|
@@ -125,6 +134,15 @@ export class Pipeline {
|
|
|
125
134
|
writable: true,
|
|
126
135
|
value: (...args) => this.chain(new BitPosCommand(args, this.commandOptions))
|
|
127
136
|
});
|
|
137
|
+
/**
|
|
138
|
+
* @see https://redis.io/commands/zdiffstore
|
|
139
|
+
*/
|
|
140
|
+
Object.defineProperty(this, "zdiffstore", {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
configurable: true,
|
|
143
|
+
writable: true,
|
|
144
|
+
value: (...args) => this.chain(new ZDiffStoreCommand(args, this.commandOptions))
|
|
145
|
+
});
|
|
128
146
|
/**
|
|
129
147
|
* @see https://redis.io/commands/dbsize
|
|
130
148
|
*/
|
|
@@ -251,6 +269,15 @@ export class Pipeline {
|
|
|
251
269
|
writable: true,
|
|
252
270
|
value: (...args) => this.chain(new GetBitCommand(args, this.commandOptions))
|
|
253
271
|
});
|
|
272
|
+
/**
|
|
273
|
+
* @see https://redis.io/commands/getdel
|
|
274
|
+
*/
|
|
275
|
+
Object.defineProperty(this, "getdel", {
|
|
276
|
+
enumerable: true,
|
|
277
|
+
configurable: true,
|
|
278
|
+
writable: true,
|
|
279
|
+
value: (...args) => this.chain(new GetDelCommand(args, this.commandOptions))
|
|
280
|
+
});
|
|
254
281
|
/**
|
|
255
282
|
* @see https://redis.io/commands/getrange
|
|
256
283
|
*/
|
|
@@ -359,6 +386,15 @@ export class Pipeline {
|
|
|
359
386
|
writable: true,
|
|
360
387
|
value: (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions))
|
|
361
388
|
});
|
|
389
|
+
/**
|
|
390
|
+
* @see https://redis.io/commands/hrandfield
|
|
391
|
+
*/
|
|
392
|
+
Object.defineProperty(this, "hrandfield", {
|
|
393
|
+
enumerable: true,
|
|
394
|
+
configurable: true,
|
|
395
|
+
writable: true,
|
|
396
|
+
value: (key, count, withValues) => this.chain(new HRandFieldCommand([key, count, withValues], this.commandOptions))
|
|
397
|
+
});
|
|
362
398
|
/**
|
|
363
399
|
* @see https://redis.io/commands/hscan
|
|
364
400
|
*/
|
|
@@ -467,6 +503,15 @@ export class Pipeline {
|
|
|
467
503
|
writable: true,
|
|
468
504
|
value: (...args) => this.chain(new LLenCommand(args, this.commandOptions))
|
|
469
505
|
});
|
|
506
|
+
/**
|
|
507
|
+
* @see https://redis.io/commands/lmove
|
|
508
|
+
*/
|
|
509
|
+
Object.defineProperty(this, "lmove", {
|
|
510
|
+
enumerable: true,
|
|
511
|
+
configurable: true,
|
|
512
|
+
writable: true,
|
|
513
|
+
value: (...args) => this.chain(new LMoveCommand(args, this.commandOptions))
|
|
514
|
+
});
|
|
470
515
|
/**
|
|
471
516
|
* @see https://redis.io/commands/lpop
|
|
472
517
|
*/
|
|
@@ -836,6 +881,15 @@ export class Pipeline {
|
|
|
836
881
|
writable: true,
|
|
837
882
|
value: (...args) => this.chain(new SMembersCommand(args, this.commandOptions))
|
|
838
883
|
});
|
|
884
|
+
/**
|
|
885
|
+
* @see https://redis.io/commands/smismember
|
|
886
|
+
*/
|
|
887
|
+
Object.defineProperty(this, "smismember", {
|
|
888
|
+
enumerable: true,
|
|
889
|
+
configurable: true,
|
|
890
|
+
writable: true,
|
|
891
|
+
value: (key, members) => this.chain(new SMIsMemberCommand([key, members], this.commandOptions))
|
|
892
|
+
});
|
|
839
893
|
/**
|
|
840
894
|
* @see https://redis.io/commands/smove
|
|
841
895
|
*/
|
|
@@ -1129,9 +1183,10 @@ export class Pipeline {
|
|
|
1129
1183
|
writable: true,
|
|
1130
1184
|
value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
|
|
1131
1185
|
});
|
|
1132
|
-
this.client = client;
|
|
1186
|
+
this.client = opts.client;
|
|
1133
1187
|
this.commands = [];
|
|
1134
|
-
this.commandOptions = commandOptions;
|
|
1188
|
+
this.commandOptions = opts.commandOptions;
|
|
1189
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1135
1190
|
}
|
|
1136
1191
|
/**
|
|
1137
1192
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/esm/pkg/redis.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, 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, SMIsMemberCommand, 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
4
|
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
5
|
+
import { ZDiffStoreCommand } from "./commands/zdiffstore.js";
|
|
5
6
|
/**
|
|
6
7
|
* Serverless redis client for upstash.
|
|
7
8
|
*/
|
|
@@ -42,6 +43,24 @@ export class Redis {
|
|
|
42
43
|
this.client.request = (req) => middleware(req, makeRequest);
|
|
43
44
|
}
|
|
44
45
|
});
|
|
46
|
+
/**
|
|
47
|
+
* Technically this is not private, we can hide it from intellisense by doing this
|
|
48
|
+
*/
|
|
49
|
+
Object.defineProperty(this, "addTelemetry", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: (telemetry) => {
|
|
54
|
+
try {
|
|
55
|
+
// @ts-ignore - The `Requester` interface does not know about this method but it will be there
|
|
56
|
+
// as long as the user uses the standard HttpClient
|
|
57
|
+
this.client.mergeTelemetry(telemetry);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// ignore
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
45
64
|
/**
|
|
46
65
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
47
66
|
*
|
|
@@ -51,7 +70,30 @@ export class Redis {
|
|
|
51
70
|
enumerable: true,
|
|
52
71
|
configurable: true,
|
|
53
72
|
writable: true,
|
|
54
|
-
value: () => new Pipeline(
|
|
73
|
+
value: () => new Pipeline({
|
|
74
|
+
client: this.client,
|
|
75
|
+
commandOptions: this.opts,
|
|
76
|
+
multiExec: false,
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
81
|
+
*
|
|
82
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
83
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
84
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link Pipeline}
|
|
87
|
+
*/
|
|
88
|
+
Object.defineProperty(this, "multi", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: () => new Pipeline({
|
|
93
|
+
client: this.client,
|
|
94
|
+
commandOptions: this.opts,
|
|
95
|
+
multiExec: true,
|
|
96
|
+
})
|
|
55
97
|
});
|
|
56
98
|
/**
|
|
57
99
|
* @see https://redis.io/commands/append
|
|
@@ -215,6 +257,15 @@ export class Redis {
|
|
|
215
257
|
writable: true,
|
|
216
258
|
value: (...args) => new GetBitCommand(args, this.opts).exec(this.client)
|
|
217
259
|
});
|
|
260
|
+
/**
|
|
261
|
+
* @see https://redis.io/commands/getdel
|
|
262
|
+
*/
|
|
263
|
+
Object.defineProperty(this, "getdel", {
|
|
264
|
+
enumerable: true,
|
|
265
|
+
configurable: true,
|
|
266
|
+
writable: true,
|
|
267
|
+
value: (...args) => new GetDelCommand(args, this.opts).exec(this.client)
|
|
268
|
+
});
|
|
218
269
|
/**
|
|
219
270
|
* @see https://redis.io/commands/getrange
|
|
220
271
|
*/
|
|
@@ -323,6 +374,16 @@ export class Redis {
|
|
|
323
374
|
writable: true,
|
|
324
375
|
value: (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client)
|
|
325
376
|
});
|
|
377
|
+
/**
|
|
378
|
+
* @see https://redis.io/commands/hrandfield
|
|
379
|
+
*/
|
|
380
|
+
Object.defineProperty(this, "hrandfield", {
|
|
381
|
+
enumerable: true,
|
|
382
|
+
configurable: true,
|
|
383
|
+
writable: true,
|
|
384
|
+
value: (key, count, withValues) => new HRandFieldCommand([key, count, withValues], this.opts)
|
|
385
|
+
.exec(this.client)
|
|
386
|
+
});
|
|
326
387
|
/**
|
|
327
388
|
* @see https://redis.io/commands/hscan
|
|
328
389
|
*/
|
|
@@ -431,6 +492,15 @@ export class Redis {
|
|
|
431
492
|
writable: true,
|
|
432
493
|
value: (...args) => new LLenCommand(args, this.opts).exec(this.client)
|
|
433
494
|
});
|
|
495
|
+
/**
|
|
496
|
+
* @see https://redis.io/commands/lmove
|
|
497
|
+
*/
|
|
498
|
+
Object.defineProperty(this, "lmove", {
|
|
499
|
+
enumerable: true,
|
|
500
|
+
configurable: true,
|
|
501
|
+
writable: true,
|
|
502
|
+
value: (...args) => new LMoveCommand(args, this.opts).exec(this.client)
|
|
503
|
+
});
|
|
434
504
|
/**
|
|
435
505
|
* @see https://redis.io/commands/lpop
|
|
436
506
|
*/
|
|
@@ -791,6 +861,15 @@ export class Redis {
|
|
|
791
861
|
writable: true,
|
|
792
862
|
value: (key, member) => new SIsMemberCommand([key, member], this.opts).exec(this.client)
|
|
793
863
|
});
|
|
864
|
+
/**
|
|
865
|
+
* @see https://redis.io/commands/smismember
|
|
866
|
+
*/
|
|
867
|
+
Object.defineProperty(this, "smismember", {
|
|
868
|
+
enumerable: true,
|
|
869
|
+
configurable: true,
|
|
870
|
+
writable: true,
|
|
871
|
+
value: (key, members) => new SMIsMemberCommand([key, members], this.opts).exec(this.client)
|
|
872
|
+
});
|
|
794
873
|
/**
|
|
795
874
|
* @see https://redis.io/commands/smembers
|
|
796
875
|
*/
|
|
@@ -949,6 +1028,15 @@ export class Redis {
|
|
|
949
1028
|
writable: true,
|
|
950
1029
|
value: (...args) => new ZCountCommand(args, this.opts).exec(this.client)
|
|
951
1030
|
});
|
|
1031
|
+
/**
|
|
1032
|
+
* @see https://redis.io/commands/zdiffstore
|
|
1033
|
+
*/
|
|
1034
|
+
Object.defineProperty(this, "zdiffstore", {
|
|
1035
|
+
enumerable: true,
|
|
1036
|
+
configurable: true,
|
|
1037
|
+
writable: true,
|
|
1038
|
+
value: (...args) => new ZDiffStoreCommand(args, this.opts).exec(this.client)
|
|
1039
|
+
});
|
|
952
1040
|
/**
|
|
953
1041
|
* @see https://redis.io/commands/zincrby
|
|
954
1042
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "../pkg/redis.js";
|
|
2
2
|
import { HttpClient } from "../pkg/http.js";
|
|
3
|
+
import { VERSION } from "../version.js";
|
|
3
4
|
/**
|
|
4
5
|
* Serverless redis client for upstash.
|
|
5
6
|
*/
|
|
@@ -15,7 +16,7 @@ export class Redis extends core.Redis {
|
|
|
15
16
|
* });
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
|
-
constructor(config) {
|
|
19
|
+
constructor(config, env) {
|
|
19
20
|
if (config.url.startsWith(" ") ||
|
|
20
21
|
config.url.endsWith(" ") ||
|
|
21
22
|
/\r|\n/.test(config.url)) {
|
|
@@ -26,10 +27,17 @@ export class Redis extends core.Redis {
|
|
|
26
27
|
/\r|\n/.test(config.token)) {
|
|
27
28
|
console.warn("The redis token contains whitespace or newline, which can cause errors!");
|
|
28
29
|
}
|
|
30
|
+
const telemetry = {};
|
|
31
|
+
if (!env?.UPSTASH_DISABLE_TELEMETRY) {
|
|
32
|
+
telemetry.platform = "cloudflare";
|
|
33
|
+
telemetry.sdk = `@upstash/redis@${VERSION}`;
|
|
34
|
+
}
|
|
29
35
|
const client = new HttpClient({
|
|
30
36
|
retry: config.retry,
|
|
31
37
|
baseUrl: config.url,
|
|
32
38
|
headers: { authorization: `Bearer ${config.token}` },
|
|
39
|
+
responseEncoding: config.responseEncoding,
|
|
40
|
+
telemetry,
|
|
33
41
|
});
|
|
34
42
|
super(client, {
|
|
35
43
|
automaticDeserialization: config.automaticDeserialization,
|
|
@@ -57,6 +65,6 @@ export class Redis extends core.Redis {
|
|
|
57
65
|
if (!token) {
|
|
58
66
|
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
|
|
59
67
|
}
|
|
60
|
-
return new Redis({ ...opts, url, token });
|
|
68
|
+
return new Redis({ ...opts, url, token }, env);
|
|
61
69
|
}
|
|
62
70
|
}
|
package/esm/platforms/fastly.js
CHANGED
|
@@ -32,6 +32,7 @@ export class Redis extends core.Redis {
|
|
|
32
32
|
retry: config.retry,
|
|
33
33
|
headers: { authorization: `Bearer ${config.token}` },
|
|
34
34
|
options: { backend: config.backend },
|
|
35
|
+
responseEncoding: config.responseEncoding,
|
|
35
36
|
});
|
|
36
37
|
super(client, {
|
|
37
38
|
automaticDeserialization: config.automaticDeserialization,
|