@upstash/redis 1.6.1-next.1 → 1.7.1-next.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 CHANGED
@@ -11,9 +11,9 @@ It is the only connectionless (HTTP based) Redis client and designed for:
11
11
 
12
12
  - Serverless functions (AWS Lambda ...)
13
13
  - Cloudflare Workers (see
14
- [the example](https://github.com/upstash/upstash-redis/tree/master/examples/cloudflare-workers))
14
+ [the example](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers))
15
15
  - Fastly Compute@Edge (see
16
- [the example](https://github.com/upstash/upstash-redis/tree/master/examples/fastly))
16
+ [the example](https://github.com/upstash/upstash-redis/tree/main/examples/fastly))
17
17
  - Next.js, Jamstack ...
18
18
  - Client side web/mobile applications
19
19
  - WebAssembly
@@ -23,11 +23,86 @@ See
23
23
  [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-api-compatibility)
24
24
  supported.
25
25
 
26
+ ## Quick Start
27
+
28
+ ### Install
29
+
30
+ #### npm
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.ts";
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
+ ### Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
85
+
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:
90
+
91
+ ```typescript
92
+ import { Redis } from "@upstash/redis/with-fetch";
93
+ ```
94
+
95
+ ### Upgrading from v0.2.0?
96
+
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).
101
+
26
102
  ## Docs
27
103
 
28
- See
29
- [the documentation](https://docs.upstash.com/redis/sdks/javascriptsdk/getstarted)
30
- for details.
104
+ See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
105
+ details.
31
106
 
32
107
  ## Contributing
33
108
 
@@ -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
  }
package/package.json CHANGED
@@ -97,5 +97,5 @@
97
97
  "types": "./types/platforms/node_with_fetch.d.ts"
98
98
  }
99
99
  },
100
- "version": "1.6.1-next.1"
100
+ "version": "1.7.1-next.1"
101
101
  }
@@ -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
  }
@@ -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
  }
@@ -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,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
@@ -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,7 @@ 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
245
  /**
246
246
  * @see https://redis.io/commands/lpush
247
247
  */
@@ -325,7 +325,7 @@ export declare class Pipeline {
325
325
  /**
326
326
  * @see https://redis.io/commands/rpop
327
327
  */
328
- rpop: <TData = string>(key: string) => this;
328
+ rpop: <TData = string>(key: string, count?: number | undefined) => this;
329
329
  /**
330
330
  * @see https://redis.io/commands/rpush
331
331
  */
@@ -52,7 +52,7 @@ export declare class Redis {
52
52
  /**
53
53
  * @see https://redis.io/commands/bitpos
54
54
  */
55
- bitpos: (key: string, start: number, end: number) => Promise<number>;
55
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => Promise<number>;
56
56
  /**
57
57
  * @see https://redis.io/commands/dbsize
58
58
  */
@@ -214,7 +214,7 @@ export declare class Redis {
214
214
  /**
215
215
  * @see https://redis.io/commands/lpop
216
216
  */
217
- lpop: <TData>(key: string) => Promise<TData | null>;
217
+ lpop: <TData>(key: string, count?: number | undefined) => Promise<TData | null>;
218
218
  /**
219
219
  * @see https://redis.io/commands/lpush
220
220
  */
@@ -298,7 +298,7 @@ export declare class Redis {
298
298
  /**
299
299
  * @see https://redis.io/commands/rpop
300
300
  */
301
- rpop: <TData = string>(key: string) => Promise<TData | null>;
301
+ rpop: <TData = string>(key: string, count?: number | undefined) => Promise<TData | null>;
302
302
  /**
303
303
  * @see https://redis.io/commands/rpush
304
304
  */