@upstash/redis 0.0.0-ci.e3757170 → 0.0.0-ci.efcbdd79

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 CHANGED
@@ -23,24 +23,6 @@ See
23
23
  [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-api-compatibility)
24
24
  supported.
25
25
 
26
- ## Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
27
-
28
- If you are running on nodejs v17 and earlier, `fetch` will not be natively
29
- supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
30
- for you. But if you are running on bare node, you need to either specify a
31
- polyfill yourself or change the import path to:
32
-
33
- ```typescript
34
- import { Redis } from "@upstash/redis/with-fetch";
35
- ```
36
-
37
- ## Upgrading from v0.2.0?
38
-
39
- Please read the
40
- [migration guide](https://github.com/upstash/upstash-redis#migrating-to-v1). For
41
- further explanation we wrote a
42
- [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
43
-
44
26
  ## Quick Start
45
27
 
46
28
  ### Install
@@ -61,133 +43,7 @@ import { Redis } from "https://deno.land/x/upstash_redis/mod.ts";
61
43
 
62
44
  Create a new redis database on [upstash](https://console.upstash.com/)
63
45
 
64
- ### Environments
65
-
66
- We support various platforms, such as nodejs, cloudflare and fastly. Platforms
67
- differ slightly when it comes to environment variables and their `fetch` api.
68
- Please use the correct import when deploying to special platforms.
69
-
70
- #### Node.js
71
-
72
- Examples: Vercel, Netlify, AWS Lambda
73
-
74
- If you are running on nodejs you can set `UPSTASH_REDIS_REST_URL` and
75
- `UPSTASH_REDIS_REST_TOKEN` as environment variable and create a redis instance
76
- like this:
77
-
78
- ```ts
79
- import { Redis } from "@upstash/redis"
80
-
81
- const redis = new Redis({
82
- url: <UPSTASH_REDIS_REST_URL>,
83
- token: <UPSTASH_REDIS_REST_TOKEN>,
84
- })
85
-
86
- // or load directly from env
87
- const redis = Redis.fromEnv()
88
- ```
89
-
90
- If you are running on nodejs v17 and earlier, `fetch` will not be natively
91
- supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
92
- for you. But if you are running on bare node, you need to either specify a
93
- polyfill yourself or change the import path to:
94
-
95
- ```typescript
96
- import { Redis } from "@upstash/redis/with-fetch";
97
- ```
98
-
99
- - [Code example](https://github.com/upstash/upstash-redis/blob/main/examples/nodejs)
100
-
101
- #### Cloudflare Workers
102
-
103
- Cloudflare handles environment variables differently than nodejs. Please add
104
- `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` using
105
- `wrangler secret put ...` or in the cloudflare dashboard.
106
-
107
- Afterwards you can create a redis instance:
108
-
109
- ```ts
110
- import { Redis } from "@upstash/redis/cloudflare"
111
-
112
- const redis = new Redis({
113
- url: <UPSTASH_REDIS_REST_URL>,
114
- token: <UPSTASH_REDIS_REST_TOKEN>,
115
- })
116
-
117
-
118
- // or load directly from global env
119
-
120
- // service worker
121
- const redis = Redis.fromEnv()
122
-
123
-
124
- // module worker
125
- export default {
126
- async fetch(request: Request, env: Bindings) {
127
- const redis = Redis.fromEnv(env)
128
- // ...
129
- }
130
- }
131
- ```
132
-
133
- - [Code example Wrangler 2](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers)
134
- - [Code example Wrangler 1](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers-with-wrangler-1)
135
- - [Documentation](https://docs.upstash.com/redis/tutorials/cloudflare_workers_with_redis)
136
-
137
- #### Fastly
138
-
139
- Fastly introduces a concept called
140
- [backend](https://developer.fastly.com/reference/api/services/backend/). You
141
- need to configure a backend in your `fastly.toml`. An example can be found
142
- [here](https://github.com/upstash/upstash-redis/blob/main/examples/fastly/fastly.toml).
143
- Until the fastly api stabilizes we recommend creating an instance manually:
144
-
145
- ```ts
146
- import { Redis } from "@upstash/redis/fastly"
147
-
148
- const redis = new Redis({
149
- url: <UPSTASH_REDIS_REST_URL>,
150
- token: <UPSTASH_REDIS_REST_TOKEN>,
151
- backend: <BACKEND_NAME>,
152
- })
153
- ```
154
-
155
- - [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/fastly)
156
- - [Documentation](https://blog.upstash.com/fastly-compute-edge-with-redi)
157
-
158
- #### Deno
159
-
160
- Examples: [Deno Deploy](https://deno.com/deploy),
161
- [Netlify Edge](https://www.netlify.com/products/edge/)
162
-
163
- ```ts
164
- import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"
165
-
166
- const redis = new Redis({
167
- url: <UPSTASH_REDIS_REST_URL>,
168
- token: <UPSTASH_REDIS_REST_TOKEN>,
169
- })
170
-
171
- // or
172
- const redis = Redis.fromEnv();
173
- ```
174
-
175
- ### Working with types
176
-
177
- Most commands allow you to provide a type to make working with typescript
178
- easier.
179
-
180
- ```ts
181
- const data = await redis.get<MyCustomType>("key");
182
- // data is typed as `MyCustomType`
183
- ```
184
-
185
- ## Migrating to v1
186
-
187
- ### Explicit authentication
188
-
189
- The library is no longer automatically trying to load connection secrets from
190
- environment variables. You must either supply them yourself:
46
+ ## Basic Usage:
191
47
 
192
48
  ```ts
193
49
  import { Redis } from "@upstash/redis"
@@ -196,146 +52,52 @@ const redis = new Redis({
196
52
  url: <UPSTASH_REDIS_REST_URL>,
197
53
  token: <UPSTASH_REDIS_REST_TOKEN>,
198
54
  })
199
- ```
200
55
 
201
- Or use one of the static constructors to load from environment variables:
56
+ // string
57
+ await redis.set('key', 'value');
58
+ let data = await redis.get('key');
59
+ console.log(data)
202
60
 
203
- ```ts
204
- // Nodejs
205
- import { Redis } from "@upstash/redis";
206
- const redis = Redis.fromEnv();
207
- ```
61
+ await redis.set('key2', 'value2', {ex: 1});
208
62
 
209
- ```ts
210
- // or when deploying to cloudflare workers
211
- import { Redis } from "@upstash/redis/cloudflare";
212
- const redis = Redis.fromEnv();
213
- ```
63
+ // sorted set
64
+ await redis.zadd('scores', { score: 1, member: 'team1' })
65
+ data = await redis.zrange('scores', 0, 100 )
66
+ console.log(data)
214
67
 
215
- ### Error handling
68
+ // list
69
+ await redis.lpush('elements', 'magnesium')
70
+ data = await redis.lrange('elements', 0, 100 )
71
+ console.log(data)
216
72
 
217
- Errors are now thrown automatically instead of being returned to you.
73
+ // hash
74
+ await redis.hset('people', {name: 'joe'})
75
+ data = await redis.hget('people', 'name' )
76
+ console.log(data)
218
77
 
219
- ```ts
220
- // old
221
- const { data, error } = await set("key", "value");
222
- if (error) {
223
- throw new Error(error);
224
- }
225
-
226
- // new
227
- const data = await redis.set("key", "value"); // error is thrown automatically
78
+ // sets
79
+ await redis.sadd('animals', 'cat')
80
+ data = await redis.spop('animals', 1)
81
+ console.log(data)
228
82
  ```
229
83
 
230
- ## Pipeline
231
-
232
- `v1.0.0` introduces redis pipelines. Pipelining commands allows you to send a
233
- single http request with multiple commands.
234
-
235
- ```ts
236
- import { Redis } from "@upstash/redis";
237
-
238
- const redis = new Redis({
239
- /* auth */
240
- });
241
-
242
- const p = redis.pipeline();
84
+ ### Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
243
85
 
244
- // Now you can chain multiple commands to create your pipeline:
245
-
246
- p.set("key", 2);
247
- p.incr("key");
248
-
249
- // or inline:
250
- p.hset("key2", "field", { hello: "world" }).hvals("key2");
251
-
252
- // Execute the pipeline once you are done building it:
253
- // `exec` returns an array where each element represents the response of a command in the pipeline.
254
- // You can optionally provide a type like this to get a typed response.
255
- const res = await p.exec<[Type1, Type2, Type3]>();
256
- ```
257
-
258
- For more information about pipelines using REST see
259
- [here](https://blog.upstash.com/pipeline).
260
-
261
- ### Advanced
262
-
263
- A low level `Command` class can be imported from `@upstash/redis` in case you
264
- need more control about types and or (de)serialization.
265
-
266
- By default all objects you are storing in redis are serialized using
267
- `JSON.stringify` and recursively deserialized as well. Here's an example how you
268
- could customize that behaviour. Keep in mind that you need to provide a `fetch`
269
- polyfill if you are running on nodejs. We recommend
270
- [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch).
271
-
272
- ```ts
273
- import { Command } from "@upstash/redis/commands"
274
- import { HttpClient } from "@upstash/redis/http"
275
-
276
- /**
277
- * TData represents what the user will enter or receive,
278
- * TResult is the raw data returned from upstash, which may need to be
279
- * transformed or parsed.
280
- */
281
- const deserialize: (raw: TResult) => TData = ...
282
-
283
- class CustomGetCommand<TData, TResult> extends Command<TData | null, TResult | null> {
284
- constructor(key: string, ) {
285
- super(["get", key], { deserialize })
286
- }
287
- }
288
-
289
- const client = new HttpClient({
290
- baseUrl: <UPSTASH_REDIS_REST_URL>,
291
- headers: {
292
- authorization: `Bearer ${<UPSTASH_REDIS_REST_TOKEN>}`,
293
- },
294
- })
295
-
296
- const res = new CustomGetCommand("key").exec(client)
297
- ```
298
-
299
- ### Additional information
300
-
301
- #### `keepalive`
302
-
303
- `@upstash/redis` is capable of reusing connections where possible to minimize
304
- latency. Connections can be reused if the client is stored in memory and not
305
- initialized with every new function invocation. The easiest way to achieve this
306
- is by creating the client outside of your handler and adding an https agent:
307
-
308
- ```ts
309
- // Nextjs api route
310
- import { Redis } from "@upstash/redis";
311
- import https from "https";
312
-
313
- const redis = Redis.fromEnv({
314
- agent: new https.Agent({ keepAlive: true }),
315
- });
86
+ If you are running on nodejs v17 and earlier, `fetch` will not be natively
87
+ supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
88
+ for you. But if you are running on bare node, you need to either specify a
89
+ polyfill yourself or change the import path to:
316
90
 
317
- export default async function (req, res) {
318
- // use redis here
319
- }
91
+ ```typescript
92
+ import { Redis } from "@upstash/redis/with-fetch";
320
93
  ```
321
94
 
322
- Whenever your hot lambda receives a new request the client is already
323
- initialized and the previously established connection to upstash is reused.
324
-
325
- #### Javascript MAX_SAFE_INTEGER
326
-
327
- Javascript can not handle numbers larger than `2^53 -1` safely and would return
328
- wrong results when trying to deserialize them. In these cases the default
329
- deserializer will return them as string instead. This might cause a mismatch
330
- with your custom types.
331
-
332
- ```ts
333
- await redis.set("key", "101600000000150081467");
334
- const res = await redis<number>("get");
335
- ```
95
+ ### Upgrading from v0.2.0?
336
96
 
337
- In this example `res` will still be a string despite the type annotation. Please
338
- keep that in mind and adjust accordingly.
97
+ Please read the
98
+ [migration guide](https://docs.upstash.com/redis/sdks/javascriptsdk/migration).
99
+ For further explanation we wrote a
100
+ [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
339
101
 
340
102
  ## Docs
341
103
 
@@ -0,0 +1,19 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/lpos
4
+ */
5
+ export class LPosCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ const args = ["lpos", cmd[0], cmd[1]];
8
+ if (typeof cmd[2]?.rank === "number") {
9
+ args.push("rank", cmd[2].rank);
10
+ }
11
+ if (typeof cmd[2]?.count === "number") {
12
+ args.push("count", cmd[2].count);
13
+ }
14
+ if (typeof cmd[2]?.maxLen === "number") {
15
+ args.push("maxLen", cmd[2].maxLen);
16
+ }
17
+ super(args, opts);
18
+ }
19
+ }
@@ -42,6 +42,7 @@ export * from "./lindex.js";
42
42
  export * from "./linsert.js";
43
43
  export * from "./llen.js";
44
44
  export * from "./lpop.js";
45
+ export * from "./lpos.js";
45
46
  export * from "./lpush.js";
46
47
  export * from "./lpushx.js";
47
48
  export * from "./lrange.js";
@@ -1,6 +1,6 @@
1
1
  import { Command } from "./command.js";
2
2
  /**
3
- * @see https://redis.io/commands/sdiffstpre
3
+ * @see https://redis.io/commands/sdiffstore
4
4
  */
5
5
  export class SDiffStoreCommand extends Command {
6
6
  constructor(cmd, opts) {
@@ -12,6 +12,12 @@ export class ZRangeCommand extends Command {
12
12
  if (opts?.byLex) {
13
13
  command.push("bylex");
14
14
  }
15
+ if (opts?.rev) {
16
+ command.push("rev");
17
+ }
18
+ if (typeof opts?.count !== "undefined" && typeof opts?.offset !== "undefined") {
19
+ command.push("limit", opts.offset, opts.count);
20
+ }
15
21
  if (opts?.withScores) {
16
22
  command.push("withscores");
17
23
  }
@@ -1,4 +1,4 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { UpstashError } from "./error.js";
3
3
  /**
4
4
  * Upstash REST API supports command pipelining to send multiple commands in
@@ -475,6 +475,15 @@ export class Pipeline {
475
475
  writable: true,
476
476
  value: (...args) => this.chain(new LPopCommand(args, this.commandOptions))
477
477
  });
478
+ /**
479
+ * @see https://redis.io/commands/lpos
480
+ */
481
+ Object.defineProperty(this, "lpos", {
482
+ enumerable: true,
483
+ configurable: true,
484
+ writable: true,
485
+ value: (...args) => this.chain(new LPosCommand(args, this.commandOptions))
486
+ });
478
487
  /**
479
488
  * @see https://redis.io/commands/lpush
480
489
  */
package/esm/pkg/redis.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { Pipeline } from "./pipeline.js";
3
3
  /**
4
4
  * Serverless redis client for upstash.
@@ -28,6 +28,18 @@ export class Redis {
28
28
  writable: true,
29
29
  value: void 0
30
30
  });
31
+ /**
32
+ * Wrap a new middleware around the HTTP client.
33
+ */
34
+ Object.defineProperty(this, "use", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: (middleware) => {
39
+ const makeRequest = this.client.request.bind(this.client);
40
+ this.client.request = (req) => middleware(req, makeRequest);
41
+ }
42
+ });
31
43
  /**
32
44
  * Create a new pipeline that allows you to send requests in bulk.
33
45
  *
@@ -426,6 +438,15 @@ export class Redis {
426
438
  writable: true,
427
439
  value: (...args) => new LPopCommand(args, this.opts).exec(this.client)
428
440
  });
441
+ /**
442
+ * @see https://redis.io/commands/lpos
443
+ */
444
+ Object.defineProperty(this, "lpos", {
445
+ enumerable: true,
446
+ configurable: true,
447
+ writable: true,
448
+ value: (...args) => new LPosCommand(args, this.opts).exec(this.client)
449
+ });
429
450
  /**
430
451
  * @see https://redis.io/commands/lpush
431
452
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/redis",
6
- "version": "v0.0.0-ci.e3757170",
6
+ "version": "v0.0.0-ci.efcbdd79",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LPosCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/lpos
7
+ */
8
+ class LPosCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ const args = ["lpos", cmd[0], cmd[1]];
11
+ if (typeof cmd[2]?.rank === "number") {
12
+ args.push("rank", cmd[2].rank);
13
+ }
14
+ if (typeof cmd[2]?.count === "number") {
15
+ args.push("count", cmd[2].count);
16
+ }
17
+ if (typeof cmd[2]?.maxLen === "number") {
18
+ args.push("maxLen", cmd[2].maxLen);
19
+ }
20
+ super(args, opts);
21
+ }
22
+ }
23
+ exports.LPosCommand = LPosCommand;
@@ -58,6 +58,7 @@ __exportStar(require("./lindex.js"), exports);
58
58
  __exportStar(require("./linsert.js"), exports);
59
59
  __exportStar(require("./llen.js"), exports);
60
60
  __exportStar(require("./lpop.js"), exports);
61
+ __exportStar(require("./lpos.js"), exports);
61
62
  __exportStar(require("./lpush.js"), exports);
62
63
  __exportStar(require("./lpushx.js"), exports);
63
64
  __exportStar(require("./lrange.js"), exports);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDiffStoreCommand = void 0;
4
4
  const command_js_1 = require("./command.js");
5
5
  /**
6
- * @see https://redis.io/commands/sdiffstpre
6
+ * @see https://redis.io/commands/sdiffstore
7
7
  */
8
8
  class SDiffStoreCommand extends command_js_1.Command {
9
9
  constructor(cmd, opts) {
@@ -15,6 +15,12 @@ class ZRangeCommand extends command_js_1.Command {
15
15
  if (opts?.byLex) {
16
16
  command.push("bylex");
17
17
  }
18
+ if (opts?.rev) {
19
+ command.push("rev");
20
+ }
21
+ if (typeof opts?.count !== "undefined" && typeof opts?.offset !== "undefined") {
22
+ command.push("limit", opts.offset, opts.count);
23
+ }
18
24
  if (opts?.withScores) {
19
25
  command.push("withscores");
20
26
  }
@@ -478,6 +478,15 @@ class Pipeline {
478
478
  writable: true,
479
479
  value: (...args) => this.chain(new mod_js_1.LPopCommand(args, this.commandOptions))
480
480
  });
481
+ /**
482
+ * @see https://redis.io/commands/lpos
483
+ */
484
+ Object.defineProperty(this, "lpos", {
485
+ enumerable: true,
486
+ configurable: true,
487
+ writable: true,
488
+ value: (...args) => this.chain(new mod_js_1.LPosCommand(args, this.commandOptions))
489
+ });
481
490
  /**
482
491
  * @see https://redis.io/commands/lpush
483
492
  */
@@ -31,6 +31,18 @@ class Redis {
31
31
  writable: true,
32
32
  value: void 0
33
33
  });
34
+ /**
35
+ * Wrap a new middleware around the HTTP client.
36
+ */
37
+ Object.defineProperty(this, "use", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: (middleware) => {
42
+ const makeRequest = this.client.request.bind(this.client);
43
+ this.client.request = (req) => middleware(req, makeRequest);
44
+ }
45
+ });
34
46
  /**
35
47
  * Create a new pipeline that allows you to send requests in bulk.
36
48
  *
@@ -429,6 +441,15 @@ class Redis {
429
441
  writable: true,
430
442
  value: (...args) => new mod_js_1.LPopCommand(args, this.opts).exec(this.client)
431
443
  });
444
+ /**
445
+ * @see https://redis.io/commands/lpos
446
+ */
447
+ Object.defineProperty(this, "lpos", {
448
+ enumerable: true,
449
+ configurable: true,
450
+ writable: true,
451
+ value: (...args) => new mod_js_1.LPosCommand(args, this.opts).exec(this.client)
452
+ });
432
453
  /**
433
454
  * @see https://redis.io/commands/lpush
434
455
  */
@@ -6,7 +6,6 @@ export declare class BitOpCommand extends Command<number, number> {
6
6
  constructor(cmd: [
7
7
  op: "and" | "or" | "xor",
8
8
  destinationKey: string,
9
- sourceKey: string,
10
9
  ...sourceKeys: string[]
11
10
  ], opts?: CommandOptions<number, number>);
12
11
  constructor(cmd: [op: "not", destinationKey: string, sourceKey: string], opts?: CommandOptions<number, number>);
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
3
3
  * @see https://redis.io/commands/bitpos
4
4
  */
5
5
  export declare class BitPosCommand extends Command<number, number> {
6
- constructor(cmd: [key: string, start: number, end: number], opts?: CommandOptions<number, number>);
6
+ constructor(cmd: [key: string, bit: 0 | 1, start?: number, end?: number], opts?: CommandOptions<number, number>);
7
7
  }
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
3
3
  * @see https://redis.io/commands/lpop
4
4
  */
5
5
  export declare class LPopCommand<TData = string> extends Command<unknown | null, TData | null> {
6
- constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
6
+ constructor(cmd: [key: string, count?: number], opts?: CommandOptions<unknown | null, TData | null>);
7
7
  }
@@ -0,0 +1,15 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/lpos
4
+ */
5
+ export declare class LPosCommand<TData = number> extends Command<TData, TData> {
6
+ constructor(cmd: [
7
+ key: string,
8
+ element: unknown,
9
+ opts?: {
10
+ rank?: number;
11
+ count?: number;
12
+ maxLen?: number;
13
+ }
14
+ ], opts?: CommandOptions<TData, TData>);
15
+ }
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
3
3
  * @see https://redis.io/commands/mget
4
4
  */
5
5
  export declare class MGetCommand<TData extends unknown[]> extends Command<(string | null)[], TData> {
6
- constructor(cmd: [...keys: [string, ...string[]]], opts?: CommandOptions<(string | null)[], TData>);
6
+ constructor(cmd: [...keys: string[]], opts?: CommandOptions<(string | null)[], TData>);
7
7
  }
@@ -42,6 +42,7 @@ export * from "./lindex.js";
42
42
  export * from "./linsert.js";
43
43
  export * from "./llen.js";
44
44
  export * from "./lpop.js";
45
+ export * from "./lpos.js";
45
46
  export * from "./lpush.js";
46
47
  export * from "./lpushx.js";
47
48
  export * from "./lrange.js";
@@ -2,6 +2,6 @@ import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
3
  * @see https://redis.io/commands/rpop
4
4
  */
5
- export declare class RPopCommand<TData = string> extends Command<unknown | null, TData | null> {
6
- constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
5
+ export declare class RPopCommand<TData extends unknown | unknown[] = string> extends Command<unknown | null, TData | null> {
6
+ constructor(cmd: [key: string, count?: number], opts?: CommandOptions<unknown | null, TData | null>);
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
- * @see https://redis.io/commands/sdiffstpre
3
+ * @see https://redis.io/commands/sdiffstore
4
4
  */
5
5
  export declare class SDiffStoreCommand extends Command<number, number> {
6
6
  constructor(cmd: [destination: string, ...keys: string[]], opts?: CommandOptions<number, number>);
@@ -2,6 +2,6 @@ import { Command, CommandOptions } from "./command.js";
2
2
  /**
3
3
  * @see https://redis.io/commands/spop
4
4
  */
5
- export declare class SPopCommand<TData> extends Command<string | null, TData | null> {
6
- constructor([key, count]: [key: string, count?: number], opts?: CommandOptions<string | null, TData | null>);
5
+ export declare class SPopCommand<TData> extends Command<string | string[] | null, TData | null> {
6
+ constructor([key, count]: [key: string, count?: number], opts?: CommandOptions<string | string[] | null, TData | null>);
7
7
  }
@@ -30,6 +30,6 @@ export declare class ZAddCommand<TData = string> extends Command<number | null,
30
30
  constructor(cmd: [
31
31
  key: string,
32
32
  opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr,
33
- ...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]
33
+ ...scoreMemberPairs: ScoreMember<TData>[]
34
34
  ], opts?: CommandOptions<number | null, number | null>);
35
35
  }
@@ -1,6 +1,7 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  export declare type ZRangeCommandOptions = {
3
3
  withScores?: boolean;
4
+ rev?: boolean;
4
5
  } & ({
5
6
  byScore: true;
6
7
  byLex?: never;
@@ -10,6 +11,12 @@ export declare type ZRangeCommandOptions = {
10
11
  } | {
11
12
  byScore?: never;
12
13
  byLex?: never;
14
+ }) & ({
15
+ offset: number;
16
+ count: number;
17
+ } | {
18
+ offset?: never;
19
+ count?: never;
13
20
  });
14
21
  /**
15
22
  * @see https://redis.io/commands/zrange
@@ -1,4 +1,4 @@
1
- import { DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
1
+ import { DelCommand, ExistsCommand, FlushAllCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
2
  import { CommandOptions } from "./commands/command.js";
3
3
  import { Requester } from "./http.js";
4
4
  import { CommandArgs } from "./types.js";
@@ -79,7 +79,7 @@ export declare class Pipeline {
79
79
  /**
80
80
  * @see https://redis.io/commands/bitpos
81
81
  */
82
- bitpos: (key: string, start: number, end: number) => this;
82
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => this;
83
83
  /**
84
84
  * @see https://redis.io/commands/dbsize
85
85
  */
@@ -241,7 +241,15 @@ export declare class Pipeline {
241
241
  /**
242
242
  * @see https://redis.io/commands/lpop
243
243
  */
244
- lpop: <TData>(key: string) => this;
244
+ lpop: <TData>(key: string, count?: number | undefined) => this;
245
+ /**
246
+ * @see https://redis.io/commands/lpos
247
+ */
248
+ lpos: <TData>(key: string, element: unknown, opts?: {
249
+ rank?: number | undefined;
250
+ count?: number | undefined;
251
+ maxLen?: number | undefined;
252
+ } | undefined) => this;
245
253
  /**
246
254
  * @see https://redis.io/commands/lpush
247
255
  */
@@ -269,7 +277,7 @@ export declare class Pipeline {
269
277
  /**
270
278
  * @see https://redis.io/commands/mget
271
279
  */
272
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => this;
280
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => this;
273
281
  /**
274
282
  * @see https://redis.io/commands/mset
275
283
  */
@@ -325,7 +333,7 @@ export declare class Pipeline {
325
333
  /**
326
334
  * @see https://redis.io/commands/rpop
327
335
  */
328
- rpop: <TData = string>(key: string) => this;
336
+ rpop: <TData = string>(key: string, count?: number | undefined) => this;
329
337
  /**
330
338
  * @see https://redis.io/commands/rpush
331
339
  */
@@ -1,5 +1,5 @@
1
- import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
- import { Requester } from "./http.js";
1
+ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
+ import { Requester, UpstashRequest, UpstashResponse } from "./http.js";
3
3
  import { Pipeline } from "./pipeline.js";
4
4
  import type { CommandArgs } from "./types.js";
5
5
  export declare type RedisOptions = {
@@ -14,7 +14,7 @@ export declare type RedisOptions = {
14
14
  * Serverless redis client for upstash.
15
15
  */
16
16
  export declare class Redis {
17
- protected readonly client: Requester;
17
+ protected client: Requester;
18
18
  protected opts?: CommandOptions<any, any>;
19
19
  /**
20
20
  * Create a new redis client
@@ -28,6 +28,10 @@ export declare class Redis {
28
28
  * ```
29
29
  */
30
30
  constructor(client: Requester, opts?: RedisOptions);
31
+ /**
32
+ * Wrap a new middleware around the HTTP client.
33
+ */
34
+ use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
31
35
  /**
32
36
  * Create a new pipeline that allows you to send requests in bulk.
33
37
  *
@@ -52,7 +56,7 @@ export declare class Redis {
52
56
  /**
53
57
  * @see https://redis.io/commands/bitpos
54
58
  */
55
- bitpos: (key: string, start: number, end: number) => Promise<number>;
59
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => Promise<number>;
56
60
  /**
57
61
  * @see https://redis.io/commands/dbsize
58
62
  */
@@ -214,7 +218,15 @@ export declare class Redis {
214
218
  /**
215
219
  * @see https://redis.io/commands/lpop
216
220
  */
217
- lpop: <TData>(key: string) => Promise<TData | null>;
221
+ lpop: <TData>(key: string, count?: number | undefined) => Promise<TData | null>;
222
+ /**
223
+ * @see https://redis.io/commands/lpos
224
+ */
225
+ lpos: <TData = number>(key: string, element: unknown, opts?: {
226
+ rank?: number | undefined;
227
+ count?: number | undefined;
228
+ maxLen?: number | undefined;
229
+ } | undefined) => Promise<TData>;
218
230
  /**
219
231
  * @see https://redis.io/commands/lpush
220
232
  */
@@ -242,7 +254,7 @@ export declare class Redis {
242
254
  /**
243
255
  * @see https://redis.io/commands/mget
244
256
  */
245
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => Promise<TData>;
257
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => Promise<TData>;
246
258
  /**
247
259
  * @see https://redis.io/commands/mset
248
260
  */
@@ -298,7 +310,7 @@ export declare class Redis {
298
310
  /**
299
311
  * @see https://redis.io/commands/rpop
300
312
  */
301
- rpop: <TData = string>(key: string) => Promise<TData | null>;
313
+ rpop: <TData = string>(key: string, count?: number | undefined) => Promise<TData | null>;
302
314
  /**
303
315
  * @see https://redis.io/commands/rpush
304
316
  */