@upstash/redis 1.0.0-alpha.4 → 1.0.1
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 +256 -0
- package/chunk-2EIGUPGW.mjs +375 -0
- package/{chunk-ZIB6XPPC.mjs → chunk-HGM7M7CJ.mjs} +9 -4
- package/{chunk-6GEVIAL6.mjs → chunk-WPH7MAB2.mjs} +1 -1
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +248 -667
- package/cloudflare.mjs +2 -2
- package/commands.d.ts +511 -4
- package/commands.js +10 -4
- package/commands.mjs +3 -1
- package/fastly.d.ts +2 -2
- package/fastly.js +248 -667
- package/fastly.mjs +2 -2
- package/index.d.ts +2 -2
- package/index.js +248 -667
- package/index.mjs +3 -3
- package/nodejs.d.ts +2 -2
- package/nodejs.js +248 -667
- package/nodejs.mjs +3 -3
- package/package.json +1 -1
- package/redis-05a33429.d.ts +976 -0
- package/zunionstore-98bb4d18.d.ts +165 -0
- package/chunk-Y5TC4HX2.mjs +0 -798
- package/redis-dd052782.d.ts +0 -962
- package/zunionstore-dffa797d.d.ts +0 -670
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Upstash Redis
|
|
2
|
+
|
|
3
|
+
An HTTP/REST based Redis client built on top of
|
|
4
|
+
[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/master/examples/cloudflare-workers))
|
|
15
|
+
- Fastly Compute@Edge (see
|
|
16
|
+
[the example](https://github.com/upstash/upstash-redis/tree/master/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 [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-api-compatibility) supported.
|
|
23
|
+
|
|
24
|
+
## Upgrading from v0.2.0?
|
|
25
|
+
|
|
26
|
+
Please read the [migration guide](https://github.com/upstash/upstash-redis#migrating-to-v1).
|
|
27
|
+
For further explanation we wrote a [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @upstash/redis
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Create database
|
|
38
|
+
|
|
39
|
+
Create a new redis database on [upstash](https://console.upstash.com/)
|
|
40
|
+
|
|
41
|
+
### Environments
|
|
42
|
+
|
|
43
|
+
We support various platforms, such as nodejs, cloudflare and fastly.
|
|
44
|
+
Platforms differ slightly when it comes to environment variables and their `fetch` api. Please use the correct import when deploying to special platforms.
|
|
45
|
+
|
|
46
|
+
#### Node.js
|
|
47
|
+
|
|
48
|
+
Examples: Vercel, Netlify, AWS Lambda
|
|
49
|
+
|
|
50
|
+
If you are running on nodejs you can set `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` as environment variable and create a redis instance like this:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { Redis } from "@upstash/redis"
|
|
54
|
+
|
|
55
|
+
const redis = new Redis({
|
|
56
|
+
url: <UPSTASH_REDIS_REST_URL>,
|
|
57
|
+
token: <UPSTASH_REDIS_REST_TOKEN>,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// or load directly from env
|
|
61
|
+
const redis = Redis.fromEnv()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/node)
|
|
65
|
+
|
|
66
|
+
#### Cloudflare Workers
|
|
67
|
+
|
|
68
|
+
Cloudflare handles environment variables differently than nodejs.
|
|
69
|
+
Please add `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` using `wrangler secret put ...` or in the cloudflare dashboard.
|
|
70
|
+
|
|
71
|
+
Afterwards you can create a redis instance:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { Redis } from "@upstash/redis/cloudflare"
|
|
75
|
+
|
|
76
|
+
const redis = new Redis({
|
|
77
|
+
url: <UPSTASH_REDIS_REST_URL>,
|
|
78
|
+
token: <UPSTASH_REDIS_REST_TOKEN>,
|
|
79
|
+
})
|
|
80
|
+
// or load directly from env
|
|
81
|
+
const redis = Redis.fromEnv()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers)
|
|
85
|
+
- [Documentation](https://docs.upstash.com/redis/tutorials/cloudflare_workers_with_redis)
|
|
86
|
+
|
|
87
|
+
#### Fastly
|
|
88
|
+
|
|
89
|
+
Fastly introduces a concept called [backend](https://developer.fastly.com/reference/api/services/backend/). You need to configure a backend in your `fastly.toml`. An example can be found [here](https://github.com/upstash/upstash-redis/blob/main/examples/fastly/fastly.toml).
|
|
90
|
+
Until the fastly api stabilizes we recommend creating an instance manually:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { Redis } from "@upstash/redis/fastly"
|
|
94
|
+
|
|
95
|
+
const redis = new Redis({
|
|
96
|
+
url: <UPSTASH_REDIS_REST_URL>,
|
|
97
|
+
token: <UPSTASH_REDIS_REST_TOKEN>,
|
|
98
|
+
backend: <BACKEND_NAME>,
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/fastly)
|
|
103
|
+
- [Documentation](https://blog.upstash.com/fastly-compute-edge-with-redi)
|
|
104
|
+
|
|
105
|
+
### Working with types
|
|
106
|
+
|
|
107
|
+
Most commands allow you to provide a type to make working with typescript easier.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const data = await redis.get<MyCustomType>("key")
|
|
111
|
+
// data is typed as `MyCustomType`
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Migrating to v1
|
|
115
|
+
|
|
116
|
+
### Explicit authentication
|
|
117
|
+
|
|
118
|
+
The library is no longer automatically trying to load connection secrets from environment variables.
|
|
119
|
+
You must either supply them yourself:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { Redis } from "@upstash/redis"
|
|
123
|
+
|
|
124
|
+
const redis = new Redis({
|
|
125
|
+
url: <UPSTASH_REDIS_REST_URL>,
|
|
126
|
+
token: <UPSTASH_REDIS_REST_TOKEN>,
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Or use one of the static constructors to load from environment variables:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// Nodejs
|
|
134
|
+
import { Redis } from "@upstash/redis"
|
|
135
|
+
const redis = Redis.fromEnv()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
// or when deploying to cloudflare workers
|
|
140
|
+
import { Redis } from "@upstash/redis/cloudflare"
|
|
141
|
+
const redis = Redis.fromEnv()
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Error handling
|
|
145
|
+
|
|
146
|
+
Errors are now thrown automatically instead of being returned to you.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
// old
|
|
150
|
+
const { data, error } = await set("key", "value")
|
|
151
|
+
if (error) {
|
|
152
|
+
throw new Error(error)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// new
|
|
156
|
+
const data = await redis.set("key", "value") // error is thrown automatically
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Pipeline
|
|
160
|
+
|
|
161
|
+
`v1.0.0` introduces redis pipelines.
|
|
162
|
+
Pipelining commands allows you to send a single http request with multiple commands.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { Redis } from "@upstash/redis"
|
|
166
|
+
|
|
167
|
+
const redis = new Redis({
|
|
168
|
+
/* auth */
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
const p = redis.pipeline()
|
|
172
|
+
|
|
173
|
+
// Now you can chain multiple commands to create your pipeline:
|
|
174
|
+
|
|
175
|
+
p.set("key", 2)
|
|
176
|
+
p.incr("key")
|
|
177
|
+
|
|
178
|
+
// or inline:
|
|
179
|
+
p.hset("key2", "field", { hello: "world" }).hvals("key2")
|
|
180
|
+
|
|
181
|
+
// Execute the pipeline once you are done building it:
|
|
182
|
+
// `exec` returns an array where each element represents the response of a command in the pipeline.
|
|
183
|
+
// You can optionally provide a type like this to get a typed response.
|
|
184
|
+
const res = await p.exec<[Type1, Type2, Type3]>()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For more information about pipelines using REST see [here](https://blog.upstash.com/pipeline).
|
|
188
|
+
|
|
189
|
+
### Advanced
|
|
190
|
+
|
|
191
|
+
A low level `Command` class can be imported from `@upstash/redis` in case you need more control about types and or (de)serialization.
|
|
192
|
+
|
|
193
|
+
By default all objects you are storing in redis are serialized using `JSON.stringify` and recursively deserialized as well. Here's an example how you could customize that behaviour. Keep in mind that you need to provide a `fetch` polyfill if you are running on nodejs. We recommend [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch).
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { Command } from "@upstash/redis/commands"
|
|
197
|
+
import { HttpClient } from "@upstash/redis/http"
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* TData represents what the user will enter or receive,
|
|
201
|
+
* TResult is the raw data returned from upstash, which may need to be
|
|
202
|
+
* transformed or parsed.
|
|
203
|
+
*/
|
|
204
|
+
const deserialize: (raw: TResult) => TData = ...
|
|
205
|
+
|
|
206
|
+
class CustomGetCommand<TData, TResult> extends Command<TData | null, TResult | null> {
|
|
207
|
+
constructor(key: string, ) {
|
|
208
|
+
super(["get", key], { deserialize })
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const client = new HttpClient({
|
|
213
|
+
baseUrl: <UPSTASH_REDIS_REST_URL>,
|
|
214
|
+
headers: {
|
|
215
|
+
authorization: `Bearer ${<UPSTASH_REDIS_REST_TOKEN>}`,
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
const res = new CustomGetCommand("key").exec(client)
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Javascript MAX_SAFE_INTEGER
|
|
224
|
+
|
|
225
|
+
Javascript can not handle numbers larger than `2^53 -1` safely and would return wrong results when trying to deserialize them.
|
|
226
|
+
In these cases the default deserializer will return them as string instead. This might cause a mismatch with your custom types.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
await redis.set("key", "101600000000150081467")
|
|
230
|
+
const res = await redis<number>("get")
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
In this example `res` will still be a string despite the type annotation.
|
|
234
|
+
Please keep that in mind and adjust accordingly.
|
|
235
|
+
|
|
236
|
+
## Docs
|
|
237
|
+
|
|
238
|
+
See [the documentation](https://docs.upstash.com/features/javascriptsdk) for details.
|
|
239
|
+
|
|
240
|
+
## Contributing
|
|
241
|
+
|
|
242
|
+
### Installing dependencies
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
pnpm install
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Database
|
|
249
|
+
|
|
250
|
+
Create a new redis database on [upstash](https://console.upstash.com/) and copy the url and token to `.env` (See `.env.example` for reference)
|
|
251
|
+
|
|
252
|
+
### Running tests
|
|
253
|
+
|
|
254
|
+
```sh
|
|
255
|
+
pnpm test
|
|
256
|
+
```
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppendCommand,
|
|
3
|
+
BitCountCommand,
|
|
4
|
+
BitOpCommand,
|
|
5
|
+
BitPosCommand,
|
|
6
|
+
DBSizeCommand,
|
|
7
|
+
DecrByCommand,
|
|
8
|
+
DecrCommand,
|
|
9
|
+
DelCommand,
|
|
10
|
+
EchoCommand,
|
|
11
|
+
ExistsCommand,
|
|
12
|
+
ExpireAtCommand,
|
|
13
|
+
ExpireCommand,
|
|
14
|
+
FlushAllCommand,
|
|
15
|
+
FlushDBCommand,
|
|
16
|
+
GetBitCommand,
|
|
17
|
+
GetCommand,
|
|
18
|
+
GetRangeCommand,
|
|
19
|
+
GetSetCommand,
|
|
20
|
+
HDelCommand,
|
|
21
|
+
HExistsCommand,
|
|
22
|
+
HGetAllCommand,
|
|
23
|
+
HGetCommand,
|
|
24
|
+
HIncrByCommand,
|
|
25
|
+
HIncrByFloatCommand,
|
|
26
|
+
HKeysCommand,
|
|
27
|
+
HLenCommand,
|
|
28
|
+
HMGetCommand,
|
|
29
|
+
HMSetCommand,
|
|
30
|
+
HScanCommand,
|
|
31
|
+
HSetCommand,
|
|
32
|
+
HSetNXCommand,
|
|
33
|
+
HStrLenCommand,
|
|
34
|
+
HValsCommand,
|
|
35
|
+
IncrByCommand,
|
|
36
|
+
IncrByFloatCommand,
|
|
37
|
+
IncrCommand,
|
|
38
|
+
KeysCommand,
|
|
39
|
+
LIndexCommand,
|
|
40
|
+
LInsertCommand,
|
|
41
|
+
LLenCommand,
|
|
42
|
+
LPopCommand,
|
|
43
|
+
LPushCommand,
|
|
44
|
+
LPushXCommand,
|
|
45
|
+
LRangeCommand,
|
|
46
|
+
LRemCommand,
|
|
47
|
+
LSetCommand,
|
|
48
|
+
LTrimCommand,
|
|
49
|
+
MGetCommand,
|
|
50
|
+
MSetCommand,
|
|
51
|
+
MSetNXCommand,
|
|
52
|
+
PExpireAtCommand,
|
|
53
|
+
PExpireCommand,
|
|
54
|
+
PSetEXCommand,
|
|
55
|
+
PTtlCommand,
|
|
56
|
+
PersistCommand,
|
|
57
|
+
PingCommand,
|
|
58
|
+
RPopCommand,
|
|
59
|
+
RPushCommand,
|
|
60
|
+
RPushXCommand,
|
|
61
|
+
RandomKeyCommand,
|
|
62
|
+
RenameCommand,
|
|
63
|
+
RenameNXCommand,
|
|
64
|
+
SAddCommand,
|
|
65
|
+
SCardCommand,
|
|
66
|
+
SDiffCommand,
|
|
67
|
+
SDiffStoreCommand,
|
|
68
|
+
SInterCommand,
|
|
69
|
+
SInterStoreCommand,
|
|
70
|
+
SIsMemberCommand,
|
|
71
|
+
SMembersCommand,
|
|
72
|
+
SMoveCommand,
|
|
73
|
+
SPopCommand,
|
|
74
|
+
SRandMemberCommand,
|
|
75
|
+
SRemCommand,
|
|
76
|
+
SScanCommand,
|
|
77
|
+
SUnionCommand,
|
|
78
|
+
SUnionStoreCommand,
|
|
79
|
+
ScanCommand,
|
|
80
|
+
SetBitCommand,
|
|
81
|
+
SetCommand,
|
|
82
|
+
SetExCommand,
|
|
83
|
+
SetNxCommand,
|
|
84
|
+
SetRangeCommand,
|
|
85
|
+
StrLenCommand,
|
|
86
|
+
TimeCommand,
|
|
87
|
+
TouchCommand,
|
|
88
|
+
TtlCommand,
|
|
89
|
+
TypeCommand,
|
|
90
|
+
UnlinkCommand,
|
|
91
|
+
ZAddCommand,
|
|
92
|
+
ZCardCommand,
|
|
93
|
+
ZCountCommand,
|
|
94
|
+
ZIncrByComand,
|
|
95
|
+
ZInterStoreCommand,
|
|
96
|
+
ZLexCountCommand,
|
|
97
|
+
ZPopMaxCommand,
|
|
98
|
+
ZPopMinCommand,
|
|
99
|
+
ZRangeCommand,
|
|
100
|
+
ZRankCommand,
|
|
101
|
+
ZRemCommand,
|
|
102
|
+
ZRemRangeByLexCommand,
|
|
103
|
+
ZRemRangeByRankCommand,
|
|
104
|
+
ZRemRangeByScoreCommand,
|
|
105
|
+
ZRevRankCommand,
|
|
106
|
+
ZScanCommand,
|
|
107
|
+
ZScoreCommand,
|
|
108
|
+
ZUnionStoreCommand
|
|
109
|
+
} from "./chunk-HGM7M7CJ.mjs";
|
|
110
|
+
import {
|
|
111
|
+
UpstashError
|
|
112
|
+
} from "./chunk-7YUZYRJS.mjs";
|
|
113
|
+
|
|
114
|
+
// pkg/pipeline.ts
|
|
115
|
+
var Pipeline = class {
|
|
116
|
+
constructor(client) {
|
|
117
|
+
this.exec = async () => {
|
|
118
|
+
if (this.commands.length === 0) {
|
|
119
|
+
throw new Error("Pipeline is empty");
|
|
120
|
+
}
|
|
121
|
+
const res = await this.client.request({
|
|
122
|
+
path: ["pipeline"],
|
|
123
|
+
body: Object.values(this.commands).map((c) => c.command)
|
|
124
|
+
});
|
|
125
|
+
return res.map(({ error, result }, i) => {
|
|
126
|
+
if (error) {
|
|
127
|
+
throw new UpstashError(`Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`);
|
|
128
|
+
}
|
|
129
|
+
return this.commands[i].deserialize(result);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
this.append = (...args) => this.chain(new AppendCommand(...args));
|
|
133
|
+
this.bitcount = (...args) => this.chain(new BitCountCommand(...args));
|
|
134
|
+
this.bitop = (op, destinationKey, sourceKey, ...sourceKeys) => this.chain(new BitOpCommand(op, destinationKey, sourceKey, ...sourceKeys));
|
|
135
|
+
this.bitpos = (...args) => this.chain(new BitPosCommand(...args));
|
|
136
|
+
this.dbsize = () => this.chain(new DBSizeCommand());
|
|
137
|
+
this.decr = (...args) => this.chain(new DecrCommand(...args));
|
|
138
|
+
this.decrby = (...args) => this.chain(new DecrByCommand(...args));
|
|
139
|
+
this.del = (...args) => this.chain(new DelCommand(...args));
|
|
140
|
+
this.echo = (...args) => this.chain(new EchoCommand(...args));
|
|
141
|
+
this.exists = (...args) => this.chain(new ExistsCommand(...args));
|
|
142
|
+
this.expire = (...args) => this.chain(new ExpireCommand(...args));
|
|
143
|
+
this.expireat = (...args) => this.chain(new ExpireAtCommand(...args));
|
|
144
|
+
this.flushall = (...args) => this.chain(new FlushAllCommand(...args));
|
|
145
|
+
this.flushdb = (...args) => this.chain(new FlushDBCommand(...args));
|
|
146
|
+
this.get = (...args) => this.chain(new GetCommand(...args));
|
|
147
|
+
this.getbit = (...args) => this.chain(new GetBitCommand(...args));
|
|
148
|
+
this.getrange = (...args) => this.chain(new GetRangeCommand(...args));
|
|
149
|
+
this.getset = (key, value) => this.chain(new GetSetCommand(key, value));
|
|
150
|
+
this.hdel = (...args) => this.chain(new HDelCommand(...args));
|
|
151
|
+
this.hexists = (...args) => this.chain(new HExistsCommand(...args));
|
|
152
|
+
this.hget = (...args) => this.chain(new HGetCommand(...args));
|
|
153
|
+
this.hgetall = (...args) => this.chain(new HGetAllCommand(...args));
|
|
154
|
+
this.hincrby = (...args) => this.chain(new HIncrByCommand(...args));
|
|
155
|
+
this.hincrbyfloat = (...args) => this.chain(new HIncrByFloatCommand(...args));
|
|
156
|
+
this.hkeys = (...args) => this.chain(new HKeysCommand(...args));
|
|
157
|
+
this.hlen = (...args) => this.chain(new HLenCommand(...args));
|
|
158
|
+
this.hmget = (...args) => this.chain(new HMGetCommand(...args));
|
|
159
|
+
this.hmset = (key, kv) => this.chain(new HMSetCommand(key, kv));
|
|
160
|
+
this.hscan = (...args) => this.chain(new HScanCommand(...args));
|
|
161
|
+
this.hset = (key, kv) => this.chain(new HSetCommand(key, kv));
|
|
162
|
+
this.hsetnx = (key, field, value) => this.chain(new HSetNXCommand(key, field, value));
|
|
163
|
+
this.hstrlen = (...args) => this.chain(new HStrLenCommand(...args));
|
|
164
|
+
this.hvals = (...args) => this.chain(new HValsCommand(...args));
|
|
165
|
+
this.incr = (...args) => this.chain(new IncrCommand(...args));
|
|
166
|
+
this.incrby = (...args) => this.chain(new IncrByCommand(...args));
|
|
167
|
+
this.incrbyfloat = (...args) => this.chain(new IncrByFloatCommand(...args));
|
|
168
|
+
this.keys = (...args) => this.chain(new KeysCommand(...args));
|
|
169
|
+
this.lindex = (...args) => this.chain(new LIndexCommand(...args));
|
|
170
|
+
this.linsert = (key, direction, pivot, value) => this.chain(new LInsertCommand(key, direction, pivot, value));
|
|
171
|
+
this.llen = (...args) => this.chain(new LLenCommand(...args));
|
|
172
|
+
this.lpop = (...args) => this.chain(new LPopCommand(...args));
|
|
173
|
+
this.lpush = (key, ...elements) => this.chain(new LPushCommand(key, ...elements));
|
|
174
|
+
this.lpushx = (key, ...elements) => this.chain(new LPushXCommand(key, ...elements));
|
|
175
|
+
this.lrange = (...args) => this.chain(new LRangeCommand(...args));
|
|
176
|
+
this.lrem = (key, count, value) => this.chain(new LRemCommand(key, count, value));
|
|
177
|
+
this.lset = (key, value, index) => this.chain(new LSetCommand(key, value, index));
|
|
178
|
+
this.ltrim = (...args) => this.chain(new LTrimCommand(...args));
|
|
179
|
+
this.mget = (...args) => this.chain(new MGetCommand(...args));
|
|
180
|
+
this.mset = (kv) => this.chain(new MSetCommand(kv));
|
|
181
|
+
this.msetnx = (kv) => this.chain(new MSetNXCommand(kv));
|
|
182
|
+
this.persist = (...args) => this.chain(new PersistCommand(...args));
|
|
183
|
+
this.pexpire = (...args) => this.chain(new PExpireCommand(...args));
|
|
184
|
+
this.pexpireat = (...args) => this.chain(new PExpireAtCommand(...args));
|
|
185
|
+
this.ping = (...args) => this.chain(new PingCommand(...args));
|
|
186
|
+
this.psetex = (key, ttl, value) => this.chain(new PSetEXCommand(key, ttl, value));
|
|
187
|
+
this.pttl = (...args) => this.chain(new PTtlCommand(...args));
|
|
188
|
+
this.randomkey = () => this.chain(new RandomKeyCommand());
|
|
189
|
+
this.rename = (...args) => this.chain(new RenameCommand(...args));
|
|
190
|
+
this.renamenx = (...args) => this.chain(new RenameNXCommand(...args));
|
|
191
|
+
this.rpop = (...args) => this.chain(new RPopCommand(...args));
|
|
192
|
+
this.rpush = (key, ...elements) => this.chain(new RPushCommand(key, ...elements));
|
|
193
|
+
this.rpushx = (key, ...elements) => this.chain(new RPushXCommand(key, ...elements));
|
|
194
|
+
this.sadd = (key, ...members) => this.chain(new SAddCommand(key, ...members));
|
|
195
|
+
this.scan = (...args) => this.chain(new ScanCommand(...args));
|
|
196
|
+
this.scard = (...args) => this.chain(new SCardCommand(...args));
|
|
197
|
+
this.sdiff = (...args) => this.chain(new SDiffCommand(...args));
|
|
198
|
+
this.sdiffstore = (...args) => this.chain(new SDiffStoreCommand(...args));
|
|
199
|
+
this.set = (key, value, opts) => this.chain(new SetCommand(key, value, opts));
|
|
200
|
+
this.setbit = (...args) => this.chain(new SetBitCommand(...args));
|
|
201
|
+
this.setex = (key, ttl, value) => this.chain(new SetExCommand(key, ttl, value));
|
|
202
|
+
this.setnx = (key, value) => this.chain(new SetNxCommand(key, value));
|
|
203
|
+
this.setrange = (...args) => this.chain(new SetRangeCommand(...args));
|
|
204
|
+
this.sinter = (...args) => this.chain(new SInterCommand(...args));
|
|
205
|
+
this.sinterstore = (...args) => this.chain(new SInterStoreCommand(...args));
|
|
206
|
+
this.sismember = (key, member) => this.chain(new SIsMemberCommand(key, member));
|
|
207
|
+
this.smembers = (...args) => this.chain(new SMembersCommand(...args));
|
|
208
|
+
this.smove = (source, destination, member) => this.chain(new SMoveCommand(source, destination, member));
|
|
209
|
+
this.spop = (...args) => this.chain(new SPopCommand(...args));
|
|
210
|
+
this.srandmember = (...args) => this.chain(new SRandMemberCommand(...args));
|
|
211
|
+
this.srem = (key, ...members) => this.chain(new SRemCommand(key, ...members));
|
|
212
|
+
this.sscan = (...args) => this.chain(new SScanCommand(...args));
|
|
213
|
+
this.strlen = (...args) => this.chain(new StrLenCommand(...args));
|
|
214
|
+
this.sunion = (...args) => this.chain(new SUnionCommand(...args));
|
|
215
|
+
this.sunionstore = (...args) => this.chain(new SUnionStoreCommand(...args));
|
|
216
|
+
this.time = () => this.chain(new TimeCommand());
|
|
217
|
+
this.touch = (...args) => this.chain(new TouchCommand(...args));
|
|
218
|
+
this.ttl = (...args) => this.chain(new TtlCommand(...args));
|
|
219
|
+
this.type = (...args) => this.chain(new TypeCommand(...args));
|
|
220
|
+
this.unlink = (...args) => this.chain(new UnlinkCommand(...args));
|
|
221
|
+
this.zadd = (...args) => {
|
|
222
|
+
if ("score" in args[1]) {
|
|
223
|
+
return this.chain(new ZAddCommand(args[0], args[1], ...args.slice(2)));
|
|
224
|
+
}
|
|
225
|
+
return this.chain(new ZAddCommand(args[0], args[1], ...args.slice(2)));
|
|
226
|
+
};
|
|
227
|
+
this.zcard = (...args) => this.chain(new ZCardCommand(...args));
|
|
228
|
+
this.zcount = (...args) => this.chain(new ZCountCommand(...args));
|
|
229
|
+
this.zincrby = (key, increment, member) => this.chain(new ZIncrByComand(key, increment, member));
|
|
230
|
+
this.zinterstore = (...args) => this.chain(new ZInterStoreCommand(...args));
|
|
231
|
+
this.zlexcount = (...args) => this.chain(new ZLexCountCommand(...args));
|
|
232
|
+
this.zpopmax = (...args) => this.chain(new ZPopMaxCommand(...args));
|
|
233
|
+
this.zpopmin = (...args) => this.chain(new ZPopMinCommand(...args));
|
|
234
|
+
this.zrange = (...args) => this.chain(new ZRangeCommand(...args));
|
|
235
|
+
this.zrank = (key, member) => this.chain(new ZRankCommand(key, member));
|
|
236
|
+
this.zrem = (key, ...members) => this.chain(new ZRemCommand(key, ...members));
|
|
237
|
+
this.zremrangebylex = (...args) => this.chain(new ZRemRangeByLexCommand(...args));
|
|
238
|
+
this.zremrangebyrank = (...args) => this.chain(new ZRemRangeByRankCommand(...args));
|
|
239
|
+
this.zremrangebyscore = (...args) => this.chain(new ZRemRangeByScoreCommand(...args));
|
|
240
|
+
this.zrevrank = (key, member) => this.chain(new ZRevRankCommand(key, member));
|
|
241
|
+
this.zscan = (...args) => this.chain(new ZScanCommand(...args));
|
|
242
|
+
this.zscore = (key, member) => this.chain(new ZScoreCommand(key, member));
|
|
243
|
+
this.zunionstore = (...args) => this.chain(new ZUnionStoreCommand(...args));
|
|
244
|
+
this.client = client;
|
|
245
|
+
this.commands = [];
|
|
246
|
+
}
|
|
247
|
+
chain(command) {
|
|
248
|
+
this.commands.push(command);
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// pkg/redis.ts
|
|
254
|
+
var Redis = class {
|
|
255
|
+
constructor(client) {
|
|
256
|
+
this.pipeline = () => new Pipeline(this.client);
|
|
257
|
+
this.append = (...args) => new AppendCommand(...args).exec(this.client);
|
|
258
|
+
this.bitcount = (...args) => new BitCountCommand(...args).exec(this.client);
|
|
259
|
+
this.bitop = (op, destinationKey, sourceKey, ...sourceKeys) => new BitOpCommand(op, destinationKey, sourceKey, ...sourceKeys).exec(this.client);
|
|
260
|
+
this.bitpos = (...args) => new BitPosCommand(...args).exec(this.client);
|
|
261
|
+
this.dbsize = () => new DBSizeCommand().exec(this.client);
|
|
262
|
+
this.decr = (...args) => new DecrCommand(...args).exec(this.client);
|
|
263
|
+
this.decrby = (...args) => new DecrByCommand(...args).exec(this.client);
|
|
264
|
+
this.del = (...args) => new DelCommand(...args).exec(this.client);
|
|
265
|
+
this.echo = (...args) => new EchoCommand(...args).exec(this.client);
|
|
266
|
+
this.exists = (...args) => new ExistsCommand(...args).exec(this.client);
|
|
267
|
+
this.expire = (...args) => new ExpireCommand(...args).exec(this.client);
|
|
268
|
+
this.expireat = (...args) => new ExpireAtCommand(...args).exec(this.client);
|
|
269
|
+
this.flushall = (...args) => new FlushAllCommand(...args).exec(this.client);
|
|
270
|
+
this.flushdb = (...args) => new FlushDBCommand(...args).exec(this.client);
|
|
271
|
+
this.get = (...args) => new GetCommand(...args).exec(this.client);
|
|
272
|
+
this.getbit = (...args) => new GetBitCommand(...args).exec(this.client);
|
|
273
|
+
this.getrange = (...args) => new GetRangeCommand(...args).exec(this.client);
|
|
274
|
+
this.getset = (key, value) => new GetSetCommand(key, value).exec(this.client);
|
|
275
|
+
this.hdel = (...args) => new HDelCommand(...args).exec(this.client);
|
|
276
|
+
this.hexists = (...args) => new HExistsCommand(...args).exec(this.client);
|
|
277
|
+
this.hget = (...args) => new HGetCommand(...args).exec(this.client);
|
|
278
|
+
this.hgetall = (...args) => new HGetAllCommand(...args).exec(this.client);
|
|
279
|
+
this.hincrby = (...args) => new HIncrByCommand(...args).exec(this.client);
|
|
280
|
+
this.hincrbyfloat = (...args) => new HIncrByFloatCommand(...args).exec(this.client);
|
|
281
|
+
this.hkeys = (...args) => new HKeysCommand(...args).exec(this.client);
|
|
282
|
+
this.hlen = (...args) => new HLenCommand(...args).exec(this.client);
|
|
283
|
+
this.hmget = (...args) => new HMGetCommand(...args).exec(this.client);
|
|
284
|
+
this.hmset = (key, kv) => new HMSetCommand(key, kv).exec(this.client);
|
|
285
|
+
this.hscan = (...args) => new HScanCommand(...args).exec(this.client);
|
|
286
|
+
this.hset = (key, kv) => new HSetCommand(key, kv).exec(this.client);
|
|
287
|
+
this.hsetnx = (key, field, value) => new HSetNXCommand(key, field, value).exec(this.client);
|
|
288
|
+
this.hstrlen = (...args) => new HStrLenCommand(...args).exec(this.client);
|
|
289
|
+
this.hvals = (...args) => new HValsCommand(...args).exec(this.client);
|
|
290
|
+
this.incr = (...args) => new IncrCommand(...args).exec(this.client);
|
|
291
|
+
this.incrby = (...args) => new IncrByCommand(...args).exec(this.client);
|
|
292
|
+
this.incrbyfloat = (...args) => new IncrByFloatCommand(...args).exec(this.client);
|
|
293
|
+
this.keys = (...args) => new KeysCommand(...args).exec(this.client);
|
|
294
|
+
this.lindex = (...args) => new LIndexCommand(...args).exec(this.client);
|
|
295
|
+
this.linsert = (key, direction, pivot, value) => new LInsertCommand(key, direction, pivot, value).exec(this.client);
|
|
296
|
+
this.llen = (...args) => new LLenCommand(...args).exec(this.client);
|
|
297
|
+
this.lpop = (...args) => new LPopCommand(...args).exec(this.client);
|
|
298
|
+
this.lpush = (key, ...elements) => new LPushCommand(key, ...elements).exec(this.client);
|
|
299
|
+
this.lpushx = (key, ...elements) => new LPushXCommand(key, ...elements).exec(this.client);
|
|
300
|
+
this.lrange = (...args) => new LRangeCommand(...args).exec(this.client);
|
|
301
|
+
this.lrem = (key, count, value) => new LRemCommand(key, count, value).exec(this.client);
|
|
302
|
+
this.lset = (key, value, index) => new LSetCommand(key, value, index).exec(this.client);
|
|
303
|
+
this.ltrim = (...args) => new LTrimCommand(...args).exec(this.client);
|
|
304
|
+
this.mget = (...args) => new MGetCommand(...args).exec(this.client);
|
|
305
|
+
this.mset = (kv) => new MSetCommand(kv).exec(this.client);
|
|
306
|
+
this.msetnx = (kv) => new MSetNXCommand(kv).exec(this.client);
|
|
307
|
+
this.persist = (...args) => new PersistCommand(...args).exec(this.client);
|
|
308
|
+
this.pexpire = (...args) => new PExpireCommand(...args).exec(this.client);
|
|
309
|
+
this.pexpireat = (...args) => new PExpireAtCommand(...args).exec(this.client);
|
|
310
|
+
this.ping = (...args) => new PingCommand(...args).exec(this.client);
|
|
311
|
+
this.psetex = (key, ttl, value) => new PSetEXCommand(key, ttl, value).exec(this.client);
|
|
312
|
+
this.pttl = (...args) => new PTtlCommand(...args).exec(this.client);
|
|
313
|
+
this.randomkey = () => new RandomKeyCommand().exec(this.client);
|
|
314
|
+
this.rename = (...args) => new RenameCommand(...args).exec(this.client);
|
|
315
|
+
this.renamenx = (...args) => new RenameNXCommand(...args).exec(this.client);
|
|
316
|
+
this.rpop = (...args) => new RPopCommand(...args).exec(this.client);
|
|
317
|
+
this.rpush = (key, ...elements) => new RPushCommand(key, ...elements).exec(this.client);
|
|
318
|
+
this.rpushx = (key, ...elements) => new RPushXCommand(key, ...elements).exec(this.client);
|
|
319
|
+
this.sadd = (key, ...members) => new SAddCommand(key, ...members).exec(this.client);
|
|
320
|
+
this.scan = (...args) => new ScanCommand(...args).exec(this.client);
|
|
321
|
+
this.scard = (...args) => new SCardCommand(...args).exec(this.client);
|
|
322
|
+
this.sdiff = (...args) => new SDiffCommand(...args).exec(this.client);
|
|
323
|
+
this.sdiffstore = (...args) => new SDiffStoreCommand(...args).exec(this.client);
|
|
324
|
+
this.set = (key, value, opts) => new SetCommand(key, value, opts).exec(this.client);
|
|
325
|
+
this.setbit = (...args) => new SetBitCommand(...args).exec(this.client);
|
|
326
|
+
this.setex = (key, ttl, value) => new SetExCommand(key, ttl, value).exec(this.client);
|
|
327
|
+
this.setnx = (key, value) => new SetNxCommand(key, value).exec(this.client);
|
|
328
|
+
this.setrange = (...args) => new SetRangeCommand(...args).exec(this.client);
|
|
329
|
+
this.sinter = (...args) => new SInterCommand(...args).exec(this.client);
|
|
330
|
+
this.sinterstore = (...args) => new SInterStoreCommand(...args).exec(this.client);
|
|
331
|
+
this.sismember = (key, member) => new SIsMemberCommand(key, member).exec(this.client);
|
|
332
|
+
this.smembers = (...args) => new SMembersCommand(...args).exec(this.client);
|
|
333
|
+
this.smove = (source, destination, member) => new SMoveCommand(source, destination, member).exec(this.client);
|
|
334
|
+
this.spop = (...args) => new SPopCommand(...args).exec(this.client);
|
|
335
|
+
this.srandmember = (...args) => new SRandMemberCommand(...args).exec(this.client);
|
|
336
|
+
this.srem = (key, ...members) => new SRemCommand(key, ...members).exec(this.client);
|
|
337
|
+
this.sscan = (...args) => new SScanCommand(...args).exec(this.client);
|
|
338
|
+
this.strlen = (...args) => new StrLenCommand(...args).exec(this.client);
|
|
339
|
+
this.sunion = (...args) => new SUnionCommand(...args).exec(this.client);
|
|
340
|
+
this.sunionstore = (...args) => new SUnionStoreCommand(...args).exec(this.client);
|
|
341
|
+
this.time = () => new TimeCommand().exec(this.client);
|
|
342
|
+
this.touch = (...args) => new TouchCommand(...args).exec(this.client);
|
|
343
|
+
this.ttl = (...args) => new TtlCommand(...args).exec(this.client);
|
|
344
|
+
this.type = (...args) => new TypeCommand(...args).exec(this.client);
|
|
345
|
+
this.unlink = (...args) => new UnlinkCommand(...args).exec(this.client);
|
|
346
|
+
this.zadd = (...args) => {
|
|
347
|
+
if ("score" in args[1]) {
|
|
348
|
+
return new ZAddCommand(args[0], args[1], ...args.slice(2)).exec(this.client);
|
|
349
|
+
}
|
|
350
|
+
return new ZAddCommand(args[0], args[1], ...args.slice(2)).exec(this.client);
|
|
351
|
+
};
|
|
352
|
+
this.zcard = (...args) => new ZCardCommand(...args).exec(this.client);
|
|
353
|
+
this.zcount = (...args) => new ZCountCommand(...args).exec(this.client);
|
|
354
|
+
this.zincrby = (key, increment, member) => new ZIncrByComand(key, increment, member).exec(this.client);
|
|
355
|
+
this.zinterstore = (...args) => new ZInterStoreCommand(...args).exec(this.client);
|
|
356
|
+
this.zlexcount = (...args) => new ZLexCountCommand(...args).exec(this.client);
|
|
357
|
+
this.zpopmax = (...args) => new ZPopMaxCommand(...args).exec(this.client);
|
|
358
|
+
this.zpopmin = (...args) => new ZPopMinCommand(...args).exec(this.client);
|
|
359
|
+
this.zrange = (...args) => new ZRangeCommand(...args).exec(this.client);
|
|
360
|
+
this.zrank = (key, member) => new ZRankCommand(key, member).exec(this.client);
|
|
361
|
+
this.zrem = (key, ...members) => new ZRemCommand(key, ...members).exec(this.client);
|
|
362
|
+
this.zremrangebylex = (...args) => new ZRemRangeByLexCommand(...args).exec(this.client);
|
|
363
|
+
this.zremrangebyrank = (...args) => new ZRemRangeByRankCommand(...args).exec(this.client);
|
|
364
|
+
this.zremrangebyscore = (...args) => new ZRemRangeByScoreCommand(...args).exec(this.client);
|
|
365
|
+
this.zrevrank = (key, member) => new ZRevRankCommand(key, member).exec(this.client);
|
|
366
|
+
this.zscan = (...args) => new ZScanCommand(...args).exec(this.client);
|
|
367
|
+
this.zscore = (key, member) => new ZScoreCommand(key, member).exec(this.client);
|
|
368
|
+
this.zunionstore = (...args) => new ZUnionStoreCommand(...args).exec(this.client);
|
|
369
|
+
this.client = client;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export {
|
|
374
|
+
Redis
|
|
375
|
+
};
|
|
@@ -4,13 +4,17 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// pkg/util.ts
|
|
6
6
|
function parseRecursive(obj) {
|
|
7
|
-
|
|
7
|
+
const parsed = Array.isArray(obj) ? obj.map((o) => {
|
|
8
8
|
try {
|
|
9
9
|
return parseRecursive(o);
|
|
10
10
|
} catch {
|
|
11
11
|
return o;
|
|
12
12
|
}
|
|
13
13
|
}) : JSON.parse(obj);
|
|
14
|
+
if (typeof parsed === "number" && parsed.toString() != obj) {
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
return parsed;
|
|
14
18
|
}
|
|
15
19
|
function parseResponse(result) {
|
|
16
20
|
try {
|
|
@@ -20,7 +24,7 @@ function parseResponse(result) {
|
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
// pkg/command.ts
|
|
27
|
+
// pkg/commands/command.ts
|
|
24
28
|
var Command = class {
|
|
25
29
|
constructor(command, opts) {
|
|
26
30
|
var _a;
|
|
@@ -300,8 +304,8 @@ var HScanCommand = class extends Command {
|
|
|
300
304
|
|
|
301
305
|
// pkg/commands/hset.ts
|
|
302
306
|
var HSetCommand = class extends Command {
|
|
303
|
-
constructor(key,
|
|
304
|
-
super(["hset", key, field, value]);
|
|
307
|
+
constructor(key, kv) {
|
|
308
|
+
super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])]);
|
|
305
309
|
}
|
|
306
310
|
};
|
|
307
311
|
|
|
@@ -951,6 +955,7 @@ var ZUnionStoreCommand = class extends Command {
|
|
|
951
955
|
};
|
|
952
956
|
|
|
953
957
|
export {
|
|
958
|
+
Command,
|
|
954
959
|
AppendCommand,
|
|
955
960
|
BitCountCommand,
|
|
956
961
|
BitOpCommand,
|