@upstash/redis 0.0.0-canary.0
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/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/cloudflare.d.mts +45 -0
- package/dist/cloudflare.d.ts +45 -0
- package/dist/cloudflare.js +3110 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/cloudflare.mjs +3083 -0
- package/dist/cloudflare.mjs.map +1 -0
- package/dist/fastly.d.mts +43 -0
- package/dist/fastly.d.ts +43 -0
- package/dist/fastly.js +3085 -0
- package/dist/fastly.js.map +1 -0
- package/dist/fastly.mjs +3058 -0
- package/dist/fastly.mjs.map +1 -0
- package/dist/nodejs.d.mts +80 -0
- package/dist/nodejs.d.ts +80 -0
- package/dist/nodejs.js +3115 -0
- package/dist/nodejs.js.map +1 -0
- package/dist/nodejs.mjs +3088 -0
- package/dist/nodejs.mjs.map +1 -0
- package/dist/redis-1238a75f.d.ts +1787 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Upstash, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Upstash Redis
|
|
2
|
+
|
|
3
|
+
`@upstash/redis` is an HTTP/REST based Redis client for typescript, built on top
|
|
4
|
+
of [Upstash REST API](https://docs.upstash.com/features/restapi).
|
|
5
|
+
|
|
6
|
+
[](https://github.com/upstash/upstash-redis/actions/workflows/tests.yaml)
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
It is the only connectionless (HTTP based) Redis client and designed for:
|
|
11
|
+
|
|
12
|
+
- Serverless functions (AWS Lambda ...)
|
|
13
|
+
- Cloudflare Workers (see
|
|
14
|
+
[the example](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers))
|
|
15
|
+
- Fastly Compute@Edge (see
|
|
16
|
+
[the example](https://github.com/upstash/upstash-redis/tree/main/examples/fastly))
|
|
17
|
+
- Next.js, Jamstack ...
|
|
18
|
+
- Client side web/mobile applications
|
|
19
|
+
- WebAssembly
|
|
20
|
+
- and other environments where HTTP is preferred over TCP.
|
|
21
|
+
|
|
22
|
+
See
|
|
23
|
+
[the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-api-compatibility)
|
|
24
|
+
supported.
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Install
|
|
29
|
+
|
|
30
|
+
#### Node.js
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @upstash/redis
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Deno
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Redis } from "https://deno.land/x/upstash_redis/mod";
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Create database
|
|
43
|
+
|
|
44
|
+
Create a new redis database on [upstash](https://console.upstash.com/)
|
|
45
|
+
|
|
46
|
+
## Basic Usage:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { Redis } from "@upstash/redis"
|
|
50
|
+
|
|
51
|
+
const redis = new Redis({
|
|
52
|
+
url: <UPSTASH_REDIS_REST_URL>,
|
|
53
|
+
token: <UPSTASH_REDIS_REST_TOKEN>,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// string
|
|
57
|
+
await redis.set('key', 'value');
|
|
58
|
+
let data = await redis.get('key');
|
|
59
|
+
console.log(data)
|
|
60
|
+
|
|
61
|
+
await redis.set('key2', 'value2', {ex: 1});
|
|
62
|
+
|
|
63
|
+
// sorted set
|
|
64
|
+
await redis.zadd('scores', { score: 1, member: 'team1' })
|
|
65
|
+
data = await redis.zrange('scores', 0, 100 )
|
|
66
|
+
console.log(data)
|
|
67
|
+
|
|
68
|
+
// list
|
|
69
|
+
await redis.lpush('elements', 'magnesium')
|
|
70
|
+
data = await redis.lrange('elements', 0, 100 )
|
|
71
|
+
console.log(data)
|
|
72
|
+
|
|
73
|
+
// hash
|
|
74
|
+
await redis.hset('people', {name: 'joe'})
|
|
75
|
+
data = await redis.hget('people', 'name' )
|
|
76
|
+
console.log(data)
|
|
77
|
+
|
|
78
|
+
// sets
|
|
79
|
+
await redis.sadd('animals', 'cat')
|
|
80
|
+
data = await redis.spop('animals', 1)
|
|
81
|
+
console.log(data)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Troubleshooting
|
|
85
|
+
|
|
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).
|
|
90
|
+
|
|
91
|
+
## Docs
|
|
92
|
+
|
|
93
|
+
See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
|
|
94
|
+
details.
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
### [Install Deno](https://deno.land/#installation)
|
|
99
|
+
|
|
100
|
+
### Database
|
|
101
|
+
|
|
102
|
+
Create a new redis database on [upstash](https://console.upstash.com/) and copy
|
|
103
|
+
the url and token
|
|
104
|
+
|
|
105
|
+
### Running tests
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
|
|
109
|
+
```
|
|
110
|
+
|
|
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
|
|
125
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { R as RedisOptions, a as RequesterConfig, b as Redis$1 } from './redis-1238a75f.js';
|
|
2
|
+
export { c as Requester, U as UpstashRequest, d as UpstashResponse } from './redis-1238a75f.js';
|
|
3
|
+
|
|
4
|
+
type Env = {
|
|
5
|
+
UPSTASH_DISABLE_TELEMETRY?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connection credentials for upstash redis.
|
|
10
|
+
* Get them from https://console.upstash.com/redis/<uuid>
|
|
11
|
+
*/
|
|
12
|
+
type RedisConfigCloudflare = {
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_REDIS_REST_URL
|
|
15
|
+
*/
|
|
16
|
+
url: string;
|
|
17
|
+
/**
|
|
18
|
+
* UPSTASH_REDIS_REST_TOKEN
|
|
19
|
+
*/
|
|
20
|
+
token: string;
|
|
21
|
+
} & RedisOptions & RequesterConfig & Env;
|
|
22
|
+
/**
|
|
23
|
+
* Serverless redis client for upstash.
|
|
24
|
+
*/
|
|
25
|
+
declare class Redis extends Redis$1 {
|
|
26
|
+
/**
|
|
27
|
+
* Create a new redis client
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const redis = new Redis({
|
|
32
|
+
* url: "<UPSTASH_REDIS_REST_URL>",
|
|
33
|
+
* token: "<UPSTASH_REDIS_REST_TOKEN>",
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
constructor(config: RedisConfigCloudflare, env?: Env);
|
|
38
|
+
static fromEnv(env?: {
|
|
39
|
+
UPSTASH_REDIS_REST_URL: string;
|
|
40
|
+
UPSTASH_REDIS_REST_TOKEN: string;
|
|
41
|
+
UPSTASH_DISABLE_TELEMETRY?: string;
|
|
42
|
+
}, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Redis, RedisConfigCloudflare };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { R as RedisOptions, a as RequesterConfig, b as Redis$1 } from './redis-1238a75f.js';
|
|
2
|
+
export { c as Requester, U as UpstashRequest, d as UpstashResponse } from './redis-1238a75f.js';
|
|
3
|
+
|
|
4
|
+
type Env = {
|
|
5
|
+
UPSTASH_DISABLE_TELEMETRY?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connection credentials for upstash redis.
|
|
10
|
+
* Get them from https://console.upstash.com/redis/<uuid>
|
|
11
|
+
*/
|
|
12
|
+
type RedisConfigCloudflare = {
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_REDIS_REST_URL
|
|
15
|
+
*/
|
|
16
|
+
url: string;
|
|
17
|
+
/**
|
|
18
|
+
* UPSTASH_REDIS_REST_TOKEN
|
|
19
|
+
*/
|
|
20
|
+
token: string;
|
|
21
|
+
} & RedisOptions & RequesterConfig & Env;
|
|
22
|
+
/**
|
|
23
|
+
* Serverless redis client for upstash.
|
|
24
|
+
*/
|
|
25
|
+
declare class Redis extends Redis$1 {
|
|
26
|
+
/**
|
|
27
|
+
* Create a new redis client
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const redis = new Redis({
|
|
32
|
+
* url: "<UPSTASH_REDIS_REST_URL>",
|
|
33
|
+
* token: "<UPSTASH_REDIS_REST_TOKEN>",
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
constructor(config: RedisConfigCloudflare, env?: Env);
|
|
38
|
+
static fromEnv(env?: {
|
|
39
|
+
UPSTASH_REDIS_REST_URL: string;
|
|
40
|
+
UPSTASH_REDIS_REST_TOKEN: string;
|
|
41
|
+
UPSTASH_DISABLE_TELEMETRY?: string;
|
|
42
|
+
}, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Redis, RedisConfigCloudflare };
|