@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.
Files changed (41) hide show
  1. package/README.md +35 -16
  2. package/dist/main/{src/client.d.ts → client.d.ts} +7 -8
  3. package/dist/main/client.js +613 -0
  4. package/dist/main/index-cjs.d.ts +1 -0
  5. package/dist/main/index-cjs.js +120 -0
  6. package/dist/main/types.d.ts +139 -0
  7. package/dist/main/{src/type.js → types.js} +0 -1
  8. package/dist/module/client.d.ts +24 -0
  9. package/dist/module/client.js +608 -0
  10. package/dist/module/index.d.ts +3 -0
  11. package/dist/module/index.js +3 -0
  12. package/dist/module/types.d.ts +139 -0
  13. package/dist/module/types.js +1 -0
  14. package/package.json +16 -25
  15. package/src/client.ts +704 -0
  16. package/src/index-cjs.ts +117 -0
  17. package/src/index.ts +118 -0
  18. package/src/types.ts +153 -0
  19. package/tsconfig.json +9 -7
  20. package/tsconfig.module.json +3 -2
  21. package/dist/main/src/client.d.ts.map +0 -1
  22. package/dist/main/src/client.js +0 -715
  23. package/dist/main/src/client.js.map +0 -1
  24. package/dist/main/src/index.d.ts +0 -73
  25. package/dist/main/src/index.d.ts.map +0 -1
  26. package/dist/main/src/index.js +0 -124
  27. package/dist/main/src/index.js.map +0 -1
  28. package/dist/main/src/type.d.ts +0 -461
  29. package/dist/main/src/type.d.ts.map +0 -1
  30. package/dist/main/src/type.js.map +0 -1
  31. package/dist/main/utils/helper.d.ts +0 -5
  32. package/dist/main/utils/helper.d.ts.map +0 -1
  33. package/dist/main/utils/helper.js +0 -20
  34. package/dist/main/utils/helper.js.map +0 -1
  35. package/dist/module/utils/helper.d.ts +0 -5
  36. package/dist/module/utils/helper.d.ts.map +0 -1
  37. package/dist/module/utils/helper.js +0 -13
  38. package/dist/module/utils/helper.js.map +0 -1
  39. package/dist/umd/upstash-redis.js +0 -1
  40. package/utils/helper.ts +0 -17
  41. 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-with-upstash))
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 Callback Style
29
+ ### Usage with Promise
30
30
 
31
31
  ```typescript
32
- import upstash from '@upstash/redis';
32
+ import { auth, set } from '@upstash/redis';
33
33
 
34
- const redis = upstash('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
34
+ auth('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
35
35
 
36
- redis.get('key', function ({ data, error }) {
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 (Promise)
42
+ ### Usage with async/await
45
43
 
46
44
  ```typescript
47
- import upstash from '@upstash/redis';
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 redis.get('key');
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 run the Redis commands directly.
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
- const { data, error } = await get('key');
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 './type';
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 Upstash from '@upstash/redis'
16
+ * import upstash from '@upstash/redis'
17
17
  *
18
- * const redis1 = new Upstash('url', token);
19
- * const redis2 = new Upstash({ url: '', token: '', edgeUrl: '', readFromEdge: false });
18
+ * const redis1 = upstash('url', token);
19
+ * const redis2 = upstash({ url: '', token: '', edgeUrl: '', readFromEdge: false });
20
20
  * ```
21
21
  */
22
- export default Upstash;
23
- declare function Upstash(url?: string, token?: string): Upstash;
24
- declare function Upstash(options?: ClientObjectProps): Upstash;
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;