Skip to content

Commit e592d94

Browse files
leibalericsam
andauthored
v4.0.0-rc.2 (#1664)
* update workflows & README * add .deepsource.toml * fix client.quit, add error events on cluster, fix some "deepsource.io" warnings * Release 4.0.0-rc.1 * add cluster.duplicate, add some tests * fix #1650 - add support for Buffer in some commands, add GET_BUFFER command * fix GET and GET_BUFFER return type * update FAQ * Update invalid code example in README.md (#1654) * Update invalid code example in README.md * Update README.md Co-authored-by: Leibale Eidelman <[email protected]> * fix #1652 * ref #1653 - better types * better types * fix 5412479 * Update GEOSEARCHSTORE.spec.ts * fix #1660 - add support for client.HSET('key', 'field', 'value') * upgrade dependencies, update README * fix #1659 - add support for db-number in client options url * fix README, remove unused import, downgrade typedoc & typedoc-plugin-markdown * update client-configurations.md * fix README * add CLUSTER_SLOTS, add some tests * fix "createClient with url" test with redis 5 * remove unused imports * Release 4.0.0-rc.2 Co-authored-by: Richard Samuelsson <[email protected]>
1 parent 77664c3 commit e592d94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1394
-971
lines changed

README.md

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,22 @@ npm install redis@next
3838
import { createClient } from 'redis';
3939

4040
(async () => {
41-
const client = createClient();
41+
const client = createClient();
4242

43-
client.on('error', (err) => console.log('Redis Client Error', err));
43+
client.on('error', (err) => console.log('Redis Client Error', err));
4444

45-
await client.connect();
45+
await client.connect();
4646

47-
await client.set('key', 'value');
48-
const value = await client.get('key');
47+
await client.set('key', 'value');
48+
const value = await client.get('key');
4949
})();
5050
```
5151

52-
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]`:
52+
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]`:
5353

5454
```typescript
5555
createClient({
56-
socket: {
57-
url: 'redis://alice:[email protected]:6380'
58-
}
56+
url: 'redis://alice:[email protected]:6380',
5957
});
6058
```
6159

@@ -79,8 +77,8 @@ Modifiers to commands are specified using a JavaScript object:
7977

8078
```typescript
8179
await client.set('key', 'value', {
82-
EX: 10,
83-
NX: true
80+
EX: 10,
81+
NX: true,
8482
});
8583
```
8684

@@ -108,11 +106,11 @@ Start a [transaction](https://redis.io/topics/transactions) by calling `.multi()
108106
```typescript
109107
await client.set('another-key', 'another-value');
110108

111-
const [ setKeyReply, otherKeyValue ] = await client.multi()
112-
.set('key', 'value')
113-
.get('another-key')
114-
.exec()
115-
]); // ['OK', 'another-value']
109+
const [setKeyReply, otherKeyValue] = await client
110+
.multi()
111+
.set('key', 'value')
112+
.get('another-key')
113+
.exec(); // ['OK', 'another-value']
116114
```
117115

118116
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.
@@ -128,10 +126,7 @@ This pattern works especially well for blocking commands—such as `BLPOP` and `
128126
```typescript
129127
import { commandOptions } from 'redis';
130128

131-
const blPopPromise = client.blPop(
132-
commandOptions({ isolated: true }),
133-
'key'
134-
);
129+
const blPopPromise = client.blPop(commandOptions({ isolated: true }), 'key');
135130

136131
await client.lPush('key', ['1', '2']);
137132

@@ -153,12 +148,12 @@ await subscriber.connect();
153148
Once you have one, simply subscribe and unsubscribe as needed:
154149

155150
```typescript
156-
await subscriber.subscribe('channel', message => {
157-
console.log(message); // 'message'
151+
await subscriber.subscribe('channel', (message) => {
152+
console.log(message); // 'message'
158153
});
159154

160155
await subscriber.pSubscribe('channe*', (message, channel) => {
161-
console.log(message, channel); // 'message', 'channel'
156+
console.log(message, channel); // 'message', 'channel'
162157
});
163158

164159
await subscriber.unsubscribe('channel');
@@ -178,26 +173,29 @@ await publisher.publish('channel', 'message');
178173

179174
```typescript
180175
for await (const key of client.scanIterator()) {
181-
// use the key!
182-
await client.get(key);
176+
// use the key!
177+
await client.get(key);
183178
}
184179
```
185180

186181
This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
187182

188183
```typescript
189-
for await (const member of client.hScanIterator('hash')) {}
190-
for await (const { field, value } of client.sScanIterator('set')) {}
191-
for await (const { member, score } of client.zScanIterator('sorted-set')) {}
184+
for await (const member of client.hScanIterator('hash')) {
185+
}
186+
for await (const { field, value } of client.sScanIterator('set')) {
187+
}
188+
for await (const { member, score } of client.zScanIterator('sorted-set')) {
189+
}
192190
```
193191

194192
You can override the default options by providing a configuration object:
195193

196194
```typescript
197195
client.scanIterator({
198-
TYPE: 'string', // `SCAN` only
199-
MATCH: 'patter*',
200-
COUNT: 100
196+
TYPE: 'string', // `SCAN` only
197+
MATCH: 'patter*',
198+
COUNT: 100,
201199
});
202200
```
203201

@@ -209,27 +207,26 @@ Define new functions using [Lua scripts](https://redis.io/commands/eval) which e
209207
import { createClient, defineScript } from 'redis';
210208

211209
(async () => {
212-
const client = createClient({
213-
scripts: {
214-
add: defineScript({
215-
NUMBER_OF_KEYS: 1,
216-
SCRIPT:
217-
'local val = redis.pcall("GET", KEYS[1]);' +
218-
'return val + ARGV[1];',
219-
transformArguments(key: string, toAdd: number): Array<string> {
220-
return [key, number.toString()];
221-
},
222-
transformReply(reply: number): number {
223-
return reply;
224-
}
225-
})
226-
}
227-
});
228-
229-
await client.connect();
230-
231-
await client.set('key', '1');
232-
await client.add('key', 2); // 3
210+
const client = createClient({
211+
scripts: {
212+
add: defineScript({
213+
NUMBER_OF_KEYS: 1,
214+
SCRIPT:
215+
"local val = redis.pcall('GET', KEYS[1]);' + 'return val + ARGV[1];",
216+
transformArguments(key: string, toAdd: number): Array<string> {
217+
return [key, number.toString()];
218+
},
219+
transformReply(reply: number): number {
220+
return reply;
221+
},
222+
}),
223+
},
224+
});
225+
226+
await client.connect();
227+
228+
await client.set('key', '1');
229+
await client.add('key', 2); // 3
233230
})();
234231
```
235232

@@ -241,22 +238,25 @@ Connecting to a cluster is a bit different. Create the client by specifying some
241238
import { createCluster } from 'redis';
242239

243240
(async () => {
244-
const cluster = createCluster({
245-
rootNodes: [{
246-
host: '10.0.0.1',
247-
port: 30001
248-
}, {
249-
host: '10.0.0.2',
250-
port: 30002
251-
}]
252-
});
253-
254-
cluster.on('error', (err) => console.log('Redis Cluster Error', err));
255-
256-
await cluster.connect();
257-
258-
await cluster.set('key', 'value');
259-
const value = await cluster.get('key');
241+
const cluster = createCluster({
242+
rootNodes: [
243+
{
244+
host: '10.0.0.1',
245+
port: 30001,
246+
},
247+
{
248+
host: '10.0.0.2',
249+
port: 30002,
250+
},
251+
],
252+
});
253+
254+
cluster.on('error', (err) => console.log('Redis Cluster Error', err));
255+
256+
await cluster.connect();
257+
258+
await cluster.set('key', 'value');
259+
const value = await cluster.get('key');
260260
})();
261261
```
262262

@@ -273,8 +273,8 @@ Of course, if you don't do something with your Promises you're certain to get [u
273273

274274
```typescript
275275
await Promise.all([
276-
client.set('Tm9kZSBSZWRpcw==', 'users:1'),
277-
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==')
276+
client.set('Tm9kZSBSZWRpcw==', 'users:1'),
277+
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw=='),
278278
]);
279279
```
280280

@@ -284,7 +284,9 @@ If you'd like to contribute, check out the [contributing guide](CONTRIBUTING.md)
284284

285285
Thank you to all the people who already contributed to Node Redis!
286286

287-
<a href="https://github.com/NodeRedis/node-redis/graphs/contributors"><img src="https://opencollective.com/node-redis/contributors.svg?width=1012" /></a>
287+
<a href="https://github.com/NodeRedis/node-redis/graphs/contributors">
288+
<img src="https://contrib.rocks/image?repo=NodeRedis/node-redis"/>
289+
</a>
288290

289291
## License
290292

docs/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ When a socket closed unexpectedly, all the commands that were already sent will
88

99
## How are commands batched?
1010

11-
Commands are pipelined using [`queueMicrotask`](https://nodejs.org/api/globals.html#globals_queuemicrotask_callback). Commands from the same "tick" will be sent in batches and respect the [`writableHighWaterMark`](https://nodejs.org/api/stream.html#stream_new_stream_writable_options).
11+
Commands are pipelined using [`queueMicrotask`](https://nodejs.org/api/globals.html#globals_queuemicrotask_callback).
1212

1313
If `socket.write()` returns `false`—meaning that ["all or part of the data was queued in user memory"](https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback:~:text=all%20or%20part%20of%20the%20data%20was%20queued%20in%20user%20memory)—the commands will stack in memory until the [`drain`](https://nodejs.org/api/net.html#net_event_drain) event is fired.

docs/client-configuration.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
# `createClient` configuration
22

3-
| Property | Default | Description |
4-
|--------------------------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
5-
| socket | | Object defining socket connection properties |
6-
| socket.url | | `[redis[s]:]//[[username][:password]@][host][:port]` |
7-
| socket.host | `'localhost'` | Hostname to connect to |
8-
| socket.port | `6379` | Port to connect to |
9-
| socket.username | | ACL username ([see ACL guide](https://redis.io/topics/acl)) |
10-
| socket.password | | ACL password or the old "--requirepass" password |
11-
| socket.connectTimeout | `5000` | The timeout for connecting to the Redis Server (in milliseconds) |
12-
| socket.noDelay | `true` | Enable/disable the use of [`Nagle's algorithm`](https://nodejs.org/api/net.html#net_socket_setnodelay_nodelay) |
13-
| socket.keepAlive | `5000` | Enable/disable the [`keep-alive`](https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay) functionality |
14-
| socket.tls | | Set to `true` to enable [TLS Configuration](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) |
15-
| socket.reconnectStrategy | `retries => Math.min(retries * 50, 500)` | A function containing the [Reconnect Strategy](#reconnect-strategy) logic |
16-
| modules | | Object defining which [Redis Modules](https://redis.io/modules) to include (TODO - document) |
17-
| scripts | | Object defining Lua scripts to use with this client. See [Lua Scripts](../README.md#lua-scripts) |
18-
| commandsQueueMaxLength | | Maximum length of the client's internal command queue |
19-
| readonly | `false` | Connect in [`READONLY`](https://redis.io/commands/readonly) mode |
20-
| legacyMode | `false` | Maintain some backwards compatibility (see the [Migration Guide](v3-to-v4.md)) |
21-
| isolationPoolOptions | | See the [Isolated Execution Guide](./isolated-execution.md) |
3+
| Property | Default | Description |
4+
|--------------------------|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| url | | `redis[s]://[[username][:password]@][host][:port][/db-number]` (see [`redis`](https://www.iana.org/assignments/uri-schemes/prov/redis) and [`rediss`](https://www.iana.org/assignments/uri-schemes/prov/rediss) IANA registration for more details) |
6+
| socket | | Object defining socket connection properties |
7+
| socket.host | `'localhost'` | Hostname to connect to |
8+
| socket.port | `6379` | Port to connect to |
9+
| socket.path | | UNIX Socket to connect to |
10+
| socket.connectTimeout | `5000` | The timeout for connecting to the Redis Server (in milliseconds) |
11+
| socket.noDelay | `true` | Enable/disable the use of [`Nagle's algorithm`](https://nodejs.org/api/net.html#net_socket_setnodelay_nodelay) |
12+
| socket.keepAlive | `5000` | Enable/disable the [`keep-alive`](https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay) functionality |
13+
| socket.tls | | Set to `true` to enable [TLS Configuration](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback) |
14+
| socket.reconnectStrategy | `retries => Math.min(retries * 50, 500)` | A function containing the [Reconnect Strategy](#reconnect-strategy) logic |
15+
| username | | ACL username ([see ACL guide](https://redis.io/topics/acl)) |
16+
| password | | ACL password or the old "--requirepass" password |
17+
| database | | Database number to connect to (see [`SELECT`](https://redis.io/commands/select) command) |
18+
| modules | | Object defining which [Redis Modules](https://redis.io/modules) to include (TODO - document) |
19+
| scripts | | Object defining Lua Scripts to use with this client (see [Lua Scripts](../README.md#lua-scripts)) |
20+
| commandsQueueMaxLength | | Maximum length of the client's internal command queue |
21+
| readonly | `false` | Connect in [`READONLY`](https://redis.io/commands/readonly) mode |
22+
| legacyMode | `false` | Maintain some backwards compatibility (see the [Migration Guide](v3-to-v4.md)) |
23+
| isolationPoolOptions | | See the [Isolated Execution Guide](./isolated-execution.md) |
2224

2325
## Reconnect Strategy
2426

0 commit comments

Comments
 (0)