@upstash/redis 1.34.1 → 1.34.3-canary
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/chunk-FC2CKVKB.mjs +3810 -0
- package/cloudflare.js +3924 -1
- package/cloudflare.mjs +95 -1
- package/fastly.js +3897 -1
- package/fastly.mjs +68 -1
- package/nodejs.js +3944 -1
- package/nodejs.mjs +115 -1
- package/package.json +1 -1
- package/chunk-6D54FT2F.mjs +0 -1
- package/chunk-JNBN5IB4.js +0 -1
package/cloudflare.mjs
CHANGED
|
@@ -1 +1,95 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
HttpClient,
|
|
3
|
+
Redis,
|
|
4
|
+
VERSION,
|
|
5
|
+
error_exports
|
|
6
|
+
} from "./chunk-FC2CKVKB.mjs";
|
|
7
|
+
|
|
8
|
+
// platforms/cloudflare.ts
|
|
9
|
+
var Redis2 = class _Redis extends Redis {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new redis client
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const redis = new Redis({
|
|
16
|
+
* url: "<UPSTASH_REDIS_REST_URL>",
|
|
17
|
+
* token: "<UPSTASH_REDIS_REST_TOKEN>",
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
constructor(config, env) {
|
|
22
|
+
if (!config.url) {
|
|
23
|
+
console.warn(
|
|
24
|
+
`[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (!config.token) {
|
|
28
|
+
console.warn(
|
|
29
|
+
`[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
|
|
33
|
+
console.warn(
|
|
34
|
+
"[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (config.token.startsWith(" ") || config.token.endsWith(" ") || /\r|\n/.test(config.token)) {
|
|
38
|
+
console.warn(
|
|
39
|
+
"[Upstash Redis] The redis token contains whitespace or newline, which can cause errors!"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const client = new HttpClient({
|
|
43
|
+
retry: config.retry,
|
|
44
|
+
baseUrl: config.url,
|
|
45
|
+
headers: { authorization: `Bearer ${config.token}` },
|
|
46
|
+
responseEncoding: config.responseEncoding,
|
|
47
|
+
signal: config.signal,
|
|
48
|
+
keepAlive: config.keepAlive,
|
|
49
|
+
readYourWrites: config.readYourWrites
|
|
50
|
+
});
|
|
51
|
+
super(client, {
|
|
52
|
+
enableTelemetry: !env?.UPSTASH_DISABLE_TELEMETRY,
|
|
53
|
+
automaticDeserialization: config.automaticDeserialization,
|
|
54
|
+
latencyLogging: config.latencyLogging,
|
|
55
|
+
enableAutoPipelining: config.enableAutoPipelining
|
|
56
|
+
});
|
|
57
|
+
this.addTelemetry({
|
|
58
|
+
platform: "cloudflare",
|
|
59
|
+
sdk: `@upstash/redis@${VERSION}`
|
|
60
|
+
});
|
|
61
|
+
if (this.enableAutoPipelining) {
|
|
62
|
+
return this.autoPipeline();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/*
|
|
66
|
+
* Create a new Upstash Redis instance from environment variables on cloudflare.
|
|
67
|
+
*
|
|
68
|
+
* This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
|
|
69
|
+
* the global namespace
|
|
70
|
+
*
|
|
71
|
+
* If you are using a module worker, please pass in the `env` object.
|
|
72
|
+
* ```ts
|
|
73
|
+
* const redis = Redis.fromEnv(env)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static fromEnv(env, opts) {
|
|
77
|
+
const url = env?.UPSTASH_REDIS_REST_URL ?? UPSTASH_REDIS_REST_URL;
|
|
78
|
+
const token = env?.UPSTASH_REDIS_REST_TOKEN ?? UPSTASH_REDIS_REST_TOKEN;
|
|
79
|
+
if (!url) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"[Upstash Redis] Unable to find environment variable: `UPSTASH_REDIS_REST_URL`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_URL`"
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (!token) {
|
|
85
|
+
console.warn(
|
|
86
|
+
"[Upstash Redis] Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`"
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return new _Redis({ ...opts, url, token }, env);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
Redis2 as Redis,
|
|
94
|
+
error_exports as errors
|
|
95
|
+
};
|