@upstash/redis 0.1.11 → 0.2.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
@@ -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,38 @@ 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().
63
60
 
64
- ```typescript
65
- import { get } from '@upstash/redis';
61
+ ## Docs
66
62
 
67
- (async () => {
68
- try {
69
- const { data, error } = await get('key');
70
- if (error) throw error;
71
- console.log(data);
72
- } catch (error) {
73
- console.error(error);
74
- }
75
- })();
76
- ```
63
+ See [the documentation](https://docs.upstash.com/features/javascriptsdk) for details.
@@ -1,158 +1,21 @@
1
- export declare type ReturnType = {
2
- data: string | number | [] | any;
3
- error: string | null;
4
- };
5
- declare type MethodReturn = Promise<ReturnType>;
6
- declare type Callback = (res: ReturnType) => any;
7
- declare type Bit = 0 | 1;
8
- declare type Infinities = '+inf' | '-inf';
9
- declare type ZSetNumber = number | Infinities | string;
1
+ import { ClientObjectProps, Upstash } from './types';
10
2
  /**
11
- * Upstash client
12
- * @param {string} url - database rest url
13
- * @param {string} token - database rest token
3
+ * Creates a Upstash Redis instance
4
+ *
5
+ * @constructor
6
+ * @param {Object} options
7
+ * @param {string} [options.url]
8
+ * @param {string} [options.token]
9
+ * @param {Object} [options.requestOptions]
10
+ *
11
+ * @example
12
+ * ```js
13
+ * import upstash from '@upstash/redis'
14
+ *
15
+ * const redis1 = upstash('url', token);
16
+ * const redis2 = upstash({ url: '', token: '', requestOptions: {} });
17
+ * ```
14
18
  */
15
- export default function client(url?: string, token?: string): {
16
- auth: (url: string, token: string) => void;
17
- append: (key: string, value: string, callback?: Callback | undefined) => MethodReturn;
18
- decr: (key: string, callback?: Callback | undefined) => MethodReturn;
19
- decrby: (key: string, decrement: number, callback?: Callback | undefined) => MethodReturn;
20
- get: (key: string, callback?: Callback | undefined) => MethodReturn;
21
- getrange: (key: string, start: number, end: number, callback?: Callback | undefined) => MethodReturn;
22
- getset: (key: string, value: string, callback?: Callback | undefined) => MethodReturn;
23
- incr: (key: string, callback?: Callback | undefined) => MethodReturn;
24
- incrby: (key: string, value: number | string, callback?: Callback | undefined) => MethodReturn;
25
- incrbyfloat: (key: string, value: number | string, callback?: Callback | undefined) => MethodReturn;
26
- mget: (values: string[], callback?: Callback | undefined) => MethodReturn;
27
- mset: (values: string[], callback?: Callback | undefined) => MethodReturn;
28
- msetnx: (values: string[], callback?: Callback | undefined) => MethodReturn;
29
- psetex: (key: string, miliseconds: number, value: string | number, callback?: Callback | undefined) => MethodReturn;
30
- set: (key: string, value: string | number, callback?: Callback | undefined) => MethodReturn;
31
- setex: (key: string, seconds: number, value: string | number, callback?: Callback | undefined) => MethodReturn;
32
- setnx: (key: string, value: string, callback?: Callback | undefined) => MethodReturn;
33
- setrange: (key: string, offset: number | string, value: string, callback?: Callback | undefined) => MethodReturn;
34
- strlen: (key: string, callback?: Callback | undefined) => MethodReturn;
35
- bitcount: (key: string, start?: number | undefined, end?: number | undefined, callback?: Callback | undefined) => MethodReturn;
36
- bitop: (operation: 'AND' | 'OR' | 'XOR' | 'NOT', destinationKey: string, sourceKeys: string[], callback?: Callback | undefined) => MethodReturn;
37
- bitpos: (key: string, bit: Bit, start?: number | undefined, end?: number | undefined, callback?: Callback | undefined) => MethodReturn;
38
- getbit: (key: string, offset: number, callback?: Callback | undefined) => MethodReturn;
39
- setbit: (key: string, offset: number, value: Bit, callback?: Callback | undefined) => MethodReturn;
40
- echo: (value: string, callback?: Callback | undefined) => MethodReturn;
41
- ping: (value?: string | undefined, callback?: Callback | undefined) => MethodReturn;
42
- hdel: (key: string, fields: string[], callback?: Callback | undefined) => MethodReturn;
43
- hexists: (key: string, field: string, callback?: Callback | undefined) => MethodReturn;
44
- hget: (key: string, field: string, callback?: Callback | undefined) => MethodReturn;
45
- hgetall: (key: string, callback?: Callback | undefined) => MethodReturn;
46
- hincrby: (key: string, field: string, increment: number | string, callback?: Callback | undefined) => MethodReturn;
47
- hincrbyfloat: (key: string, field: string, increment: number | string, callback?: Callback | undefined) => MethodReturn;
48
- hkeys: (key: string, callback?: Callback | undefined) => MethodReturn;
49
- hlen: (key: string, callback?: Callback | undefined) => MethodReturn;
50
- hmget: (key: string, fields: string[], callback?: Callback | undefined) => MethodReturn;
51
- hmset: (key: string, values: string[], callback?: Callback | undefined) => MethodReturn;
52
- hset: (key: string, values: string[], callback?: Callback | undefined) => MethodReturn;
53
- hsetnx: (key: string, field: string, value: string, callback?: Callback | undefined) => MethodReturn;
54
- hvals: (key: string, callback?: Callback | undefined) => MethodReturn;
55
- hscan: (key: string, cursor: number, options?: {
56
- match?: string | number | undefined;
57
- count?: string | number | undefined;
58
- } | undefined, callback?: Callback | undefined) => MethodReturn;
59
- del: (keys: string[], callback?: Callback | undefined) => MethodReturn;
60
- exists: (keys: string[], callback?: Callback | undefined) => MethodReturn;
61
- expire: (key: string, seconds: number, callback?: Callback | undefined) => MethodReturn;
62
- expireat: (key: string, timestamp: number | string, callback?: Callback | undefined) => MethodReturn;
63
- keys: (pattern: string, callback?: Callback | undefined) => MethodReturn;
64
- persist: (key: string, callback?: Callback | undefined) => MethodReturn;
65
- pexpire: (key: string, miliseconds: number, callback?: Callback | undefined) => MethodReturn;
66
- pexpireat: (key: string, miliseconds: number, callback?: Callback | undefined) => MethodReturn;
67
- pttl: (key: string, callback?: Callback | undefined) => MethodReturn;
68
- randomkey: (callback?: Callback | undefined) => MethodReturn;
69
- rename: (key: string, newkey: string, callback?: Callback | undefined) => MethodReturn;
70
- renamenx: (key: string, newkey: string, callback?: Callback | undefined) => MethodReturn;
71
- scan: (cursor: number, opitons?: {
72
- match?: string | number | undefined;
73
- count?: string | number | undefined;
74
- } | undefined, callback?: Callback | undefined) => MethodReturn;
75
- touch: (keys: string[], callback?: Callback | undefined) => MethodReturn;
76
- ttl: (key: string, callback?: Callback | undefined) => MethodReturn;
77
- type: (key: string, callback?: Callback | undefined) => MethodReturn;
78
- unlink: (keys: string[], callback?: Callback | undefined) => MethodReturn;
79
- lindex: (key: string, index: number, callback?: Callback | undefined) => MethodReturn;
80
- linsert: (key: string, option: 'BEFORE' | 'AFTER', pivot: string, element: string, callback?: Callback | undefined) => MethodReturn;
81
- llen: (key: string, callback?: Callback | undefined) => MethodReturn;
82
- lpop: (key: string, callback?: Callback | undefined) => MethodReturn;
83
- lpush: (key: string, elements: string[], callback?: Callback | undefined) => MethodReturn;
84
- lpushx: (key: string, elements: string[], callback?: Callback | undefined) => MethodReturn;
85
- lrange: (key: string, start: number, stop: number, callback?: Callback | undefined) => MethodReturn;
86
- lrem: (key: string, count: number, element: string, callback?: Callback | undefined) => MethodReturn;
87
- lset: (key: string, index: number, element: string, callback?: Callback | undefined) => MethodReturn;
88
- ltrim: (key: string, start: number, stop: number, callback?: Callback | undefined) => MethodReturn;
89
- rpop: (key: string, callback?: Callback | undefined) => MethodReturn;
90
- rpoplpush: (source: string, destination: string, callback?: Callback | undefined) => MethodReturn;
91
- rpush: (key: string, elements: string[], callback?: Callback | undefined) => MethodReturn;
92
- rpushx: (key: string, elements: string[], callback?: Callback | undefined) => MethodReturn;
93
- dbsize: (callback?: Callback | undefined) => MethodReturn;
94
- flushall: (mode?: "ASYNC" | undefined, callback?: Callback | undefined) => MethodReturn;
95
- flushdb: (mode?: "ASYNC" | undefined, callback?: Callback | undefined) => MethodReturn;
96
- info: (callback?: Callback | undefined) => MethodReturn;
97
- time: (callback?: Callback | undefined) => MethodReturn;
98
- sadd: (key: string, members: string[], callback?: Callback | undefined) => MethodReturn;
99
- scard: (key: string, callback?: Callback | undefined) => MethodReturn;
100
- sdiff: (keys: string[], callback?: Callback | undefined) => MethodReturn;
101
- sdiffstore: (destination: string, keys: string[], callback?: Callback | undefined) => MethodReturn;
102
- sinter: (keys: string[], callback?: Callback | undefined) => MethodReturn;
103
- sinterstore: (destination: string, keys: string[], callback?: Callback | undefined) => MethodReturn;
104
- sismember: (key: string, member: string, callback?: Callback | undefined) => MethodReturn;
105
- smembers: (key: string, callback?: Callback | undefined) => MethodReturn;
106
- smove: (source: string, destination: string, member: string, callback?: Callback | undefined) => MethodReturn;
107
- spop: (key: string, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
108
- srandmember: (key: string, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
109
- srem: (key: string, members: string[], callback?: Callback | undefined) => MethodReturn;
110
- sunion: (keys: string[], callback?: Callback | undefined) => MethodReturn;
111
- sunionstore: (destination: string, keys: string[], callback?: Callback | undefined) => MethodReturn;
112
- zadd: (key: string, values: ZSetNumber[], options?: (({
113
- xx?: boolean | undefined;
114
- } | {
115
- nx?: boolean | undefined;
116
- }) & {
117
- ch?: boolean | undefined;
118
- incr: boolean;
119
- }) | undefined, callback?: Callback | undefined) => MethodReturn;
120
- zcard: (key: string, callback?: Callback | undefined) => MethodReturn;
121
- zcount: (key: string, min: ZSetNumber, max: ZSetNumber, callback?: Callback | undefined) => MethodReturn;
122
- zincrby: (key: string, increment: number | string, member: string, callback?: Callback | undefined) => MethodReturn;
123
- zinterstore: (destination: string, keys: string[], options?: {
124
- weights?: number[] | undefined;
125
- aggregate?: "MIN" | "MAX" | "SUM" | undefined;
126
- } | undefined, callback?: Callback | undefined) => MethodReturn;
127
- zlexcount: (key: string, min: ZSetNumber, max: ZSetNumber, callback?: Callback | undefined) => MethodReturn;
128
- zpopmax: (key: string, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
129
- zpopmin: (key: string, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
130
- zrange: (key: string, min: ZSetNumber, max: ZSetNumber, options?: {
131
- withScores: boolean;
132
- } | undefined, callback?: Callback | undefined) => MethodReturn;
133
- zrangebylex: (key: string, min: ZSetNumber, max: ZSetNumber, offset?: number | undefined, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
134
- zrangebyscore: (key: string, min: ZSetNumber, max: ZSetNumber, options?: {
135
- withScores?: boolean | undefined;
136
- limit?: {
137
- offset: number;
138
- count: number;
139
- } | undefined;
140
- } | undefined, callback?: Callback | undefined) => MethodReturn;
141
- zrank: (key: string, member: string, callback?: Callback | undefined) => MethodReturn;
142
- zrem: (key: string, members: string[], callback?: Callback | undefined) => MethodReturn;
143
- zremrangebylex: (key: string, min: ZSetNumber, max: ZSetNumber, callback?: Callback | undefined) => MethodReturn;
144
- zremrangebyrank: (key: string, start: number, stop: number, callback?: Callback | undefined) => MethodReturn;
145
- zremrangebyscore: (key: string, min: ZSetNumber, max: ZSetNumber, callback?: Callback | undefined) => MethodReturn;
146
- zrevrange: (key: string, start: number, stop: number, options?: {
147
- withScores: boolean;
148
- } | undefined, callback?: Callback | undefined) => MethodReturn;
149
- zrevrangebylex: (key: string, max: ZSetNumber, min: ZSetNumber, offset?: number | undefined, count?: number | undefined, callback?: Callback | undefined) => MethodReturn;
150
- zrevrangebyscore: (key: string, min: ZSetNumber, max: ZSetNumber, callback?: Callback | undefined) => MethodReturn;
151
- zscore: (key: string, member: string, callback?: Callback | undefined) => MethodReturn;
152
- zunionstore: (destination: string, keys: string[], options?: {
153
- weights?: number[] | undefined;
154
- aggregate?: "MIN" | "MAX" | "SUM" | undefined;
155
- } | undefined, callback?: Callback | undefined) => MethodReturn;
156
- };
157
- export {};
158
- //# sourceMappingURL=client.d.ts.map
19
+ declare function upstash(options?: ClientObjectProps): Upstash;
20
+ declare function upstash(url?: string, token?: string): Upstash;
21
+ export default upstash;