@upstash/redis 0.1.2 → 0.1.6
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 +35 -16
- package/dist/main/{src/client.d.ts → client.d.ts} +7 -8
- package/dist/main/client.js +613 -0
- package/dist/main/index-cjs.d.ts +1 -0
- package/dist/main/index-cjs.js +120 -0
- package/dist/main/types.d.ts +139 -0
- package/dist/main/{src/type.js → types.js} +0 -1
- package/dist/module/client.d.ts +24 -0
- package/dist/module/client.js +608 -0
- package/dist/module/index.d.ts +3 -0
- package/dist/module/index.js +3 -0
- package/dist/module/types.d.ts +139 -0
- package/dist/module/types.js +1 -0
- package/package.json +16 -25
- package/src/client.ts +704 -0
- package/src/index-cjs.ts +117 -0
- package/src/index.ts +118 -0
- package/src/types.ts +153 -0
- package/tsconfig.json +9 -7
- package/tsconfig.module.json +3 -2
- package/dist/main/src/client.d.ts.map +0 -1
- package/dist/main/src/client.js +0 -715
- package/dist/main/src/client.js.map +0 -1
- package/dist/main/src/index.d.ts +0 -73
- package/dist/main/src/index.d.ts.map +0 -1
- package/dist/main/src/index.js +0 -124
- package/dist/main/src/index.js.map +0 -1
- package/dist/main/src/type.d.ts +0 -461
- package/dist/main/src/type.d.ts.map +0 -1
- package/dist/main/src/type.js.map +0 -1
- package/dist/main/utils/helper.d.ts +0 -5
- package/dist/main/utils/helper.d.ts.map +0 -1
- package/dist/main/utils/helper.js +0 -20
- package/dist/main/utils/helper.js.map +0 -1
- package/dist/module/utils/helper.d.ts +0 -5
- package/dist/module/utils/helper.d.ts.map +0 -1
- package/dist/module/utils/helper.js +0 -13
- package/dist/module/utils/helper.js.map +0 -1
- package/dist/umd/upstash-redis.js +0 -1
- package/utils/helper.ts +0 -17
- package/webpack.config.js +0 -34
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ An HTTP/REST based Redis client built on top of [Upstash REST API](https://docs.
|
|
|
9
9
|
It is the only connectionless (HTTP based) Redis client and designed for:
|
|
10
10
|
|
|
11
11
|
- Serverless functions (AWS Lambda ...)
|
|
12
|
-
- Cloudflare Workers (see [the example](https://github.com/upstash/upstash-redis/tree/master/examples/workers
|
|
12
|
+
- Cloudflare Workers (see [the example](https://github.com/upstash/upstash-redis/tree/master/examples/cloudflare-workers))
|
|
13
13
|
- Fastly Compute@Edge
|
|
14
14
|
- Next.js, Jamstack ...
|
|
15
15
|
- Client side web/mobile applications
|
|
@@ -26,51 +26,70 @@ See [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-ap
|
|
|
26
26
|
npm install @upstash/redis
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
### Usage with
|
|
29
|
+
### Usage with Promise
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
|
-
import
|
|
32
|
+
import { auth, set } from '@upstash/redis';
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
auth('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
if (error) {
|
|
38
|
-
return console.error(error);
|
|
39
|
-
}
|
|
36
|
+
set('key', 'value').then(({ data }) => {
|
|
40
37
|
console.log(data);
|
|
38
|
+
// -> "OK"
|
|
41
39
|
});
|
|
42
40
|
```
|
|
43
41
|
|
|
44
|
-
### Usage with async/await
|
|
42
|
+
### Usage with async/await
|
|
45
43
|
|
|
46
44
|
```typescript
|
|
47
|
-
import
|
|
48
|
-
|
|
49
|
-
const redis = upstash('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
|
|
45
|
+
import { set } from '@upstash/redis';
|
|
50
46
|
|
|
51
47
|
(async () => {
|
|
52
48
|
try {
|
|
53
|
-
const { data, error } = await
|
|
49
|
+
const { data, error } = await set('key', 'value');
|
|
54
50
|
if (error) throw error;
|
|
55
51
|
console.log(data);
|
|
52
|
+
// -> "OK"
|
|
56
53
|
} catch (error) {
|
|
57
54
|
console.error(error);
|
|
58
55
|
}
|
|
59
56
|
})();
|
|
60
57
|
```
|
|
61
58
|
|
|
62
|
-
If you define `UPSTASH_REDIS_REST_URL` and` UPSTASH_REDIS_REST_TOKEN` environment variables, you can
|
|
59
|
+
> If you define `UPSTASH_REDIS_REST_URL` and` UPSTASH_REDIS_REST_TOKEN` environment variables, you can skip the auth().
|
|
60
|
+
|
|
61
|
+
### Edge Support
|
|
62
|
+
|
|
63
|
+
Once you set `edgeUrl`, all read commands are fetched using edge url. The REST URL is used for write/update commands.
|
|
63
64
|
|
|
64
65
|
```typescript
|
|
65
|
-
import { get } from '@upstash/redis';
|
|
66
|
+
import { auth, get } from '@upstash/redis';
|
|
67
|
+
|
|
68
|
+
auth({
|
|
69
|
+
url: 'UPSTASH_REDIS_REST_URL',
|
|
70
|
+
token: 'UPSTASH_REDIS_REST_TOKEN',
|
|
71
|
+
edgeUrl: 'UPSTASH_REDIS_EDGE_URL',
|
|
72
|
+
});
|
|
66
73
|
|
|
67
74
|
(async () => {
|
|
68
75
|
try {
|
|
69
|
-
|
|
76
|
+
// the below reads using edge url
|
|
77
|
+
const { data, error, metadata } = await get('key');
|
|
70
78
|
if (error) throw error;
|
|
71
79
|
console.log(data);
|
|
80
|
+
// -> null | string
|
|
81
|
+
console.log(metadata);
|
|
82
|
+
// -> { edge: boolean, cache: null | 'miss' | 'hit' }
|
|
83
|
+
|
|
84
|
+
// the below reads using REST url (non-edge)
|
|
85
|
+
const get1 = await get('key', { edge: false });
|
|
86
|
+
if (get1.error) throw get1.error;
|
|
72
87
|
} catch (error) {
|
|
73
88
|
console.error(error);
|
|
74
89
|
}
|
|
75
90
|
})();
|
|
76
91
|
```
|
|
92
|
+
|
|
93
|
+
## Docs
|
|
94
|
+
|
|
95
|
+
See [the documentation](https://docs.upstash.com/features/javascriptsdk) for details.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientObjectProps, Upstash } from './
|
|
1
|
+
import { ClientObjectProps, Upstash } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a Upstash Redis instance
|
|
4
4
|
*
|
|
@@ -13,13 +13,12 @@ import { ClientObjectProps, Upstash } from './type';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```js
|
|
16
|
-
* import
|
|
16
|
+
* import upstash from '@upstash/redis'
|
|
17
17
|
*
|
|
18
|
-
* const redis1 =
|
|
19
|
-
* const redis2 =
|
|
18
|
+
* const redis1 = upstash('url', token);
|
|
19
|
+
* const redis2 = upstash({ url: '', token: '', edgeUrl: '', readFromEdge: false });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
declare function
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=client.d.ts.map
|
|
22
|
+
declare function upstash(options?: ClientObjectProps): Upstash;
|
|
23
|
+
declare function upstash(url?: string, token?: string): Upstash;
|
|
24
|
+
export default upstash;
|