redis 4.0.0-rc.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/node-redis.iml" filepath="$PROJECT_DIR$/.idea/node-redis.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
package/README.md CHANGED
@@ -1,2 +1,312 @@
1
- # redis
2
- The sources and docs for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.
1
+ # Node-Redis
2
+
3
+ [![Tests](https://img.shields.io/github/workflow/status/redis/node-redis/Tests/master.svg?label=tests)](https://codecov.io/gh/redis/node-redis)
4
+ [![Coverage](https://codecov.io/gh/redis/node-redis/branch/master/graph/badge.svg?token=xcfqHhJC37)](https://codecov.io/gh/redis/node-redis)
5
+ [![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://codecov.io/gh/redis/node-redis)
6
+ [![Chat](https://img.shields.io/discord/697882427875393627.svg)](https://discord.gg/XMMVgxUm)
7
+
8
+ node-redis is a modern, high performance [Redis](https://redis.io) client for Node.js with built-in support for Redis 6.2 commands and modules including [RediSearch](https://redisearch.io) and [RedisJSON](https://redisjson.io).
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install redis
14
+ ```
15
+
16
+ > :warning: The new interface is clean and cool, but if you have an existing codebase, you'll want to read the [migration guide](./docs/v3-to-v4.md).
17
+
18
+ ## Usage
19
+
20
+ ### Basic Example
21
+
22
+ ```typescript
23
+ import { createClient } from 'redis';
24
+
25
+ (async () => {
26
+ const client = createClient();
27
+
28
+ client.on('error', (err) => console.log('Redis Client Error', err));
29
+
30
+ await client.connect();
31
+
32
+ await client.set('key', 'value');
33
+ const value = await client.get('key');
34
+ })();
35
+ ```
36
+
37
+ The above code connects to localhost on port 6379. To connect to a different host or port, use a connection string in the format `redis[s]://[[username][:password]@][host][:port][/db-number]`:
38
+
39
+ ```typescript
40
+ createClient({
41
+ url: 'redis://alice:foobared@awesome.redis.server:6380'
42
+ });
43
+ ```
44
+
45
+ You can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in the [client configuration guide](./docs/client-configuration.md).
46
+
47
+ ### Redis Commands
48
+
49
+ There is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed using the raw Redis command names (`HSET`, `HGETALL`, etc.) and a friendlier camel-cased version (`hSet`, `hGetAll`, etc.):
50
+
51
+ ```typescript
52
+ // raw Redis commands
53
+ await client.HSET('key', 'field', 'value');
54
+ await client.HGETALL('key');
55
+
56
+ // friendly JavaScript commands
57
+ await client.hSet('key', 'field', 'value');
58
+ await client.hGetAll('key');
59
+ ```
60
+
61
+ Modifiers to commands are specified using a JavaScript object:
62
+
63
+ ```typescript
64
+ await client.set('key', 'value', {
65
+ EX: 10,
66
+ NX: true
67
+ });
68
+ ```
69
+
70
+ Replies will be transformed into useful data structures:
71
+
72
+ ```typescript
73
+ await client.hGetAll('key'); // { field1: 'value1', field2: 'value2' }
74
+ await client.hVals('key'); // ['value1', 'value2']
75
+ ```
76
+
77
+ ### Unsupported Redis Commands
78
+
79
+ If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use `.sendCommand()`:
80
+
81
+ ```typescript
82
+ await client.sendCommand(['SET', 'key', 'value', 'NX']); // 'OK'
83
+
84
+ await client.sendCommand(['HGETALL', 'key']); // ['key1', 'field1', 'key2', 'field2']
85
+ ```
86
+
87
+ ### Transactions (Multi/Exec)
88
+
89
+ Start a [transaction](https://redis.io/topics/transactions) by calling `.multi()`, then chaining your commands. When you're done, call `.exec()` and you'll get an array back with your results:
90
+
91
+ ```typescript
92
+ await client.set('another-key', 'another-value');
93
+
94
+ const [setKeyReply, otherKeyValue] = await client
95
+ .multi()
96
+ .set('key', 'value')
97
+ .get('another-key')
98
+ .exec(); // ['OK', 'another-value']
99
+ ```
100
+
101
+ You can also [watch](https://redis.io/topics/transactions#optimistic-locking-using-check-and-set) keys by calling `.watch()`. Your transaction will abort if any of the watched keys change.
102
+
103
+ To dig deeper into transactions, check out the [Isolated Execution Guide](./docs/isolated-execution.md).
104
+
105
+ ### Blocking Commands
106
+
107
+ Any command can be run on a new connection by specifying the `isolated` option. The newly created connection is closed when the command's `Promise` is fulfilled.
108
+
109
+ This pattern works especially well for blocking commands—such as `BLPOP` and `BLMOVE`:
110
+
111
+ ```typescript
112
+ import { commandOptions } from 'redis';
113
+
114
+ const blPopPromise = client.blPop(commandOptions({ isolated: true }), 'key', 0);
115
+
116
+ await client.lPush('key', ['1', '2']);
117
+
118
+ await blPopPromise; // '2'
119
+ ```
120
+
121
+ To learn more about isolated execution, check out the [guide](./docs/isolated-execution.md).
122
+
123
+ ### Pub/Sub
124
+
125
+ Subscribing to a channel requires a dedicated stand-alone connection. You can easily get one by `.duplicate()`ing an existing Redis connection.
126
+
127
+ ```typescript
128
+ const subscriber = client.duplicate();
129
+
130
+ await subscriber.connect();
131
+ ```
132
+
133
+ Once you have one, simply subscribe and unsubscribe as needed:
134
+
135
+ ```typescript
136
+ await subscriber.subscribe('channel', (message) => {
137
+ console.log(message); // 'message'
138
+ });
139
+
140
+ await subscriber.pSubscribe('channe*', (message, channel) => {
141
+ console.log(message, channel); // 'message', 'channel'
142
+ });
143
+
144
+ await subscriber.unsubscribe('channel');
145
+
146
+ await subscriber.pUnsubscribe('channe*');
147
+ ```
148
+
149
+ Publish a message on a channel:
150
+
151
+ ```typescript
152
+ await publisher.publish('channel', 'message');
153
+ ```
154
+
155
+ There is support for buffers as well:
156
+
157
+ ```typescript
158
+ await subscriber.subscribe('channel', (message) => {
159
+ console.log(message); // <Buffer 6d 65 73 73 61 67 65>
160
+ }, true);
161
+
162
+ await subscriber.pSubscribe('channe*', (message, channel) => {
163
+ console.log(message, channel); // <Buffer 6d 65 73 73 61 67 65>, <Buffer 63 68 61 6e 6e 65 6c>
164
+ }, true);
165
+ ```
166
+
167
+ ### Scan Iterator
168
+
169
+ [`SCAN`](https://redis.io/commands/scan) results can be looped over using [async iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator):
170
+
171
+ ```typescript
172
+ for await (const key of client.scanIterator()) {
173
+ // use the key!
174
+ await client.get(key);
175
+ }
176
+ ```
177
+
178
+ This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
179
+
180
+ ```typescript
181
+ for await (const { field, value } of client.hScanIterator('hash')) {}
182
+ for await (const member of client.sScanIterator('set')) {}
183
+ for await (const { score, member } of client.zScanIterator('sorted-set')) {}
184
+ ```
185
+
186
+ You can override the default options by providing a configuration object:
187
+
188
+ ```typescript
189
+ client.scanIterator({
190
+ TYPE: 'string', // `SCAN` only
191
+ MATCH: 'patter*',
192
+ COUNT: 100
193
+ });
194
+ ```
195
+
196
+ ### Lua Scripts
197
+
198
+ Define new functions using [Lua scripts](https://redis.io/commands/eval) which execute on the Redis server:
199
+
200
+ ```typescript
201
+ import { createClient, defineScript } from 'redis';
202
+
203
+ (async () => {
204
+ const client = createClient({
205
+ scripts: {
206
+ add: defineScript({
207
+ NUMBER_OF_KEYS: 1,
208
+ SCRIPT:
209
+ 'local val = redis.pcall("GET", KEYS[1]);' +
210
+ 'return val + ARGV[1];',
211
+ transformArguments(key: string, toAdd: number): Array<string> {
212
+ return [key, toAdd.toString()];
213
+ },
214
+ transformReply(reply: number): number {
215
+ return reply;
216
+ }
217
+ })
218
+ }
219
+ });
220
+
221
+ await client.connect();
222
+
223
+ await client.set('key', '1');
224
+ await client.add('key', 2); // 3
225
+ })();
226
+ ```
227
+
228
+ ### Disconnecting
229
+
230
+ There are two functions that disconnect a client from the Redis server. In most scenarios you should use `.quit()` to ensure that pending commands are sent to Redis before closing a connection.
231
+
232
+ #### `.QUIT()`/`.quit()`
233
+
234
+ Gracefully close a client's connection to Redis, by sending the [`QUIT`](https://redis.io/commands/quit) command to the server. Before quitting, the client executes any remaining commands in its queue, and will receive replies from Redis for each of them.
235
+
236
+ ```typescript
237
+ const [ping, get, quit] = await Promise.all([
238
+ client.ping(),
239
+ client.get('key'),
240
+ client.quit()
241
+ ]); // ['PONG', null, 'OK']
242
+
243
+ try {
244
+ await client.get('key');
245
+ } catch (err) {
246
+ // ClosedClient Error
247
+ }
248
+ ```
249
+
250
+ #### `.disconnect()`
251
+
252
+ Forcibly close a client's connection to Redis immediately. Calling `disconnect` will not send further pending commands to the Redis server, or wait for or parse outstanding responses.
253
+
254
+ ```typescript
255
+ await client.disconnect();
256
+ ```
257
+
258
+ ### Auto-Pipelining
259
+
260
+ Node Redis will automatically pipeline requests that are made during the same "tick".
261
+
262
+ ```typescript
263
+ client.set('Tm9kZSBSZWRpcw==', 'users:1');
264
+ client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==');
265
+ ```
266
+
267
+ Of course, if you don't do something with your Promises you're certain to get [unhandled Promise exceptions](https://nodejs.org/api/process.html#process_event_unhandledrejection). To take advantage of auto-pipelining and handle your Promises, use `Promise.all()`.
268
+
269
+ ```typescript
270
+ await Promise.all([
271
+ client.set('Tm9kZSBSZWRpcw==', 'users:1'),
272
+ client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==')
273
+ ]);
274
+ ```
275
+
276
+ ### Clustering
277
+
278
+ Check out the [Clustering Guide](./docs/clustering.md) when using Node Redis to connect to a Redis Cluster.
279
+
280
+ ## Supported Redis versions
281
+
282
+ Node Redis is supported with the following versions of Redis:
283
+
284
+ | Version | Supported |
285
+ |---------|--------------------|
286
+ | 6.2.z | :heavy_check_mark: |
287
+ | 6.0.z | :heavy_check_mark: |
288
+ | 5.y.z | :heavy_check_mark: |
289
+ | < 5.0 | :x: |
290
+
291
+ > Node Redis should work with older versions of Redis, but it is not fully tested and we cannot offer support.
292
+
293
+ ## Packages
294
+
295
+ | Name | Description |
296
+ |-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
297
+ | [redis](./) | [![Downloads](https://img.shields.io/npm/dm/redis.svg)](https://www.npmjs.com/package/redis/v/next) [![Version](https://img.shields.io/npm/v/redis/next.svg)](https://www.npmjs.com/package/redis/v/next) |
298
+ | [@node-redis/client](./packages/client) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/client.svg)](https://www.npmjs.com/package/@node-redis/client/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/client/next.svg)](https://www.npmjs.com/package/@node-redis/client/v/next) |
299
+ | [@node-redis/json](./packages/json) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/json.svg)](https://www.npmjs.com/package/@node-redis/json/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/json/next.svg)](https://www.npmjs.com/package/@node-redis/json/v/next) [Redis JSON](https://oss.redis.com/redisjson/) commands |
300
+ | [@node-redis/search](./packages/search) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/search.svg)](https://www.npmjs.com/package/@node-redis/search/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/search/next.svg)](https://www.npmjs.com/package/@node-redis/search/v/next) [Redis Search](https://oss.redis.com/redisearch/) commands |
301
+
302
+ ## Contributing
303
+
304
+ If you'd like to contribute, check out the [contributing guide](CONTRIBUTING.md).
305
+
306
+ Thank you to all the people who already contributed to Node Redis!
307
+
308
+ [![Contributors](https://contrib.rocks/image?repo=redis/node-redis)](https://github.com/redis/node-redis/graphs/contributors)
309
+
310
+ ## License
311
+
312
+ This repository is licensed under the "MIT" license. See [LICENSE](LICENSE).
package/dump.rdb ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redis",
3
- "version": "4.0.0-rc.4",
3
+ "version": "4.0.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,14 +17,14 @@
17
17
  "build-all": "npm run build:client && npm run build:test-utils && npm run build:modules && npm run build"
18
18
  },
19
19
  "dependencies": {
20
- "@node-redis/client": "^1.0.0-rc.0",
21
- "@node-redis/json": "^1.0.0-rc.0",
22
- "@node-redis/search": "^1.0.0-rc.0"
20
+ "@node-redis/client": "^1.0.0",
21
+ "@node-redis/json": "^1.0.0",
22
+ "@node-redis/search": "^1.0.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@tsconfig/node12": "^1.0.9",
26
- "release-it": "^14.11.7",
27
- "typescript": "^4.4.4"
26
+ "release-it": "^14.11.8",
27
+ "typescript": "^4.5.2"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
@@ -0,0 +1,72 @@
1
+ import { createCluster } from 'redis';
2
+ import { strict as assert } from 'assert';
3
+ import { promises as fs } from 'fs';
4
+
5
+ const cluster = createCluster({
6
+ rootNodes: [{
7
+ socket: {
8
+ host: 'redis-14416.ned.shahar.demo.redislabs.com',
9
+ port: 14416
10
+ }
11
+ }],
12
+ defaults: {
13
+ password: 'osscluster'
14
+ }
15
+ });
16
+
17
+ cluster.on('error', err => console.error('Redis Cluster Error', err));
18
+
19
+ try {
20
+ await cluster.connect();
21
+
22
+ await Promise.all([
23
+ ...cluster.getMasters().map(({ client }) => client.flushAll()),
24
+ fs.writeFile('./error.log', '')
25
+ ]);
26
+
27
+ await promiseConcurrency(setAndGet, { end: 500000, concurrency: 1000 });
28
+ } finally {
29
+ await cluster.disconnect();
30
+ }
31
+
32
+ async function setAndGet(i) {
33
+ const str = i.toString();
34
+
35
+ await cluster.set(str, str);
36
+
37
+ assert.equal(
38
+ await cluster.get(str),
39
+ str
40
+ );
41
+ }
42
+
43
+ function promiseConcurrency(fn, { start = 0, end, concurrency }) {
44
+ return new Promise(resolve => {
45
+ let num = start,
46
+ inProgress = 0;
47
+
48
+ function run() {
49
+ ++inProgress;
50
+
51
+ const i = num++;
52
+ if (i % 1000 === 0) {
53
+ console.log('!!!', i);
54
+ }
55
+
56
+ fn(i)
57
+ .finally(() => --inProgress)
58
+ .then(() => {
59
+ if (num < end) {
60
+ run();
61
+ } else if (inProgress === 0) {
62
+ resolve();
63
+ }
64
+ })
65
+ .catch(err => fs.appendFile('./error.log', `${i.toString()} - ${err.toString()}\n\n-------\n\n`));
66
+ }
67
+
68
+ for (let i = 0; i < concurrency; i++) {
69
+ run();
70
+ }
71
+ });
72
+ }
File without changes
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "node-redis-scripts",
3
+ "lockfileVersion": 2,
4
+ "requires": true,
5
+ "packages": {
6
+ "..": {
7
+ "version": "4.0.0-rc.4",
8
+ "license": "MIT",
9
+ "workspaces": [
10
+ "./packages/*"
11
+ ],
12
+ "dependencies": {
13
+ "@node-redis/client": "^1.0.0-rc.0",
14
+ "@node-redis/json": "^1.0.0-rc.0",
15
+ "@node-redis/search": "^1.0.0-rc.0"
16
+ },
17
+ "devDependencies": {
18
+ "@tsconfig/node12": "^1.0.9",
19
+ "release-it": "^14.11.7",
20
+ "typescript": "^4.4.4"
21
+ }
22
+ },
23
+ "node_modules/redis": {
24
+ "resolved": "..",
25
+ "link": true
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "node-redis-scripts",
3
+ "lockfileVersion": 2,
4
+ "requires": true,
5
+ "packages": {
6
+ "": {
7
+ "name": "node-redis-scripts",
8
+ "dependencies": {
9
+ "redis": "../"
10
+ }
11
+ },
12
+ "..": {
13
+ "version": "4.0.0-rc.4",
14
+ "license": "MIT",
15
+ "workspaces": [
16
+ "./packages/*"
17
+ ],
18
+ "dependencies": {
19
+ "@node-redis/client": "^1.0.0-rc.0",
20
+ "@node-redis/json": "^1.0.0-rc.0",
21
+ "@node-redis/search": "^1.0.0-rc.0"
22
+ },
23
+ "devDependencies": {
24
+ "@tsconfig/node12": "^1.0.9",
25
+ "release-it": "^14.11.7",
26
+ "typescript": "^4.4.4"
27
+ }
28
+ },
29
+ "node_modules/redis": {
30
+ "resolved": "..",
31
+ "link": true
32
+ }
33
+ },
34
+ "dependencies": {
35
+ "redis": {
36
+ "version": "file:..",
37
+ "requires": {
38
+ "@node-redis/client": "^1.0.0-rc.0",
39
+ "@node-redis/json": "^1.0.0-rc.0",
40
+ "@node-redis/search": "^1.0.0-rc.0",
41
+ "@tsconfig/node12": "^1.0.9",
42
+ "release-it": "^14.11.7",
43
+ "typescript": "^4.4.4"
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "node-redis-scripts",
3
+ "private": true,
4
+ "type": "module",
5
+ "dependencies": {
6
+ "redis": "../"
7
+ }
8
+ }
9
+