Skip to content

Commit eb47bb0

Browse files
leibaleguyroyse
andcommitted
some docs
Co-authored-by: Guy Royse <guy@guyroyse.com>
1 parent 8ef0e47 commit eb47bb0

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

docs/command-options.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Command Options
2+
3+
> :warning: The command options API in v5 has breaking changes from the previous version. For more details, refer to the [v4-to-v5 guide](./v4-to-v5.md#command-options).
4+
5+
TODO: "proxy client" concept
6+
7+
## Type Mapping
8+
9+
TODO [RESP](./RESP.md)
10+
11+
`withTypeMapping`
12+
13+
```javascript
14+
await client.get('key'); // `string | null`
15+
16+
const proxyClient = client.withTypeMapping({
17+
[TYPES.BLOB_STRING]: Buffer
18+
});
19+
20+
await proxyClient.get('key'); // `Buffer | null`
21+
```
22+
23+
## Abort Signal
24+
25+
TODO
26+
27+
`withAbortSignal`
28+
29+
## ASAP
30+
31+
TODO
32+
33+
`asap`
34+
35+
## `withCommandOptions`
36+
37+
TODO

docs/scan-iterators.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Scan Iterators
2+
3+
> :warning: The scan iterators API in v5 has breaking changes from the previous version. For more details, refer to the [v4-to-v5 guide](./v4-to-v5.md#scan-iterators).
4+
5+
[`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):
6+
7+
```typescript
8+
for await (const keys of client.scanIterator()) {
9+
const values = await client.mGet(keys);
10+
}
11+
```
12+
13+
This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
14+
15+
```typescript
16+
for await (const entries of client.hScanIterator('hash')) {}
17+
for await (const members of client.sScanIterator('set')) {}
18+
for await (const membersWithScores of client.zScanIterator('sorted-set')) {}
19+
```
20+
21+
You can override the default options by providing a configuration object:
22+
23+
```typescript
24+
client.scanIterator({
25+
TYPE: 'string', // `SCAN` only
26+
MATCH: 'patter*',
27+
COUNT: 100
28+
});
29+
```

docs/v4-to-v5.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ With the new API, instead of passing the options directly to the commands we use
2222
await client.get('key'); // `string | null`
2323

2424
const proxyClient = client.withCommandOptions({
25-
flags: {
25+
typeMapping: {
2626
[TYPES.BLOB_STRING]: Buffer
2727
}
2828
});
@@ -33,10 +33,13 @@ await proxyClient.get('key'); // `Buffer | null`
3333
`withCommandOptions` can be used to override all of the command options, without reusing any existing ones.
3434

3535
To override just a specific option, use the following functions:
36-
- `withFlags` - override `flags` only.
36+
- `withTypeMapping` - override `typeMapping` only.
37+
- `withAbortSignal` - override `abortSignal` only.
3738
- `asap` - override `asap` to `true`.
3839
- `isolated` - override `isolated` to `true`.
3940

41+
[TODO](./command-options.md)
42+
4043
## Quit VS Disconnect
4144

4245
The `QUIT` command has been deprecated in Redis 7.2 and should now also be considered deprecated in Node-Redis. Instead of sending a `QUIT` command to the server, the client can simply close the network connection.
@@ -45,9 +48,24 @@ The `QUIT` command has been deprecated in Redis 7.2 and should now also be consi
4548

4649
## Scan Iterators
4750

48-
TODO
49-
Yields chunks instead of individual items. Allows multi key operations.
50-
See the [Scan Iterators guide](./scan-iterators.md).
51+
Iterator commands like `SCAN`, `HSCAN`, `SSCAN`, and `ZSCAN` return collections of elements (depending on the data type). However, v4 iterators loop over these collections and yield individual items:
52+
53+
```javascript
54+
for await (const key of client.scanIterator()) {
55+
console.log(key, await client.get(key));
56+
}
57+
```
58+
59+
This mismatch can be awkward and makes "multi-key" commands like `MGET`, `UNLINK`, etc. pointless. So, in v5 the iterators now yield a collection instead of an element:
60+
61+
```javascript
62+
for await (const keys of client.scanIterator()) {
63+
// we can now meaningfully utilize "multi-key" commands
64+
console.log(keys, await client.mGet(keys));
65+
}
66+
```
67+
68+
for more information, see the [Scan Iterators guide](./scan-iterators.md).
5169

5270
## Legacy Mode
5371

0 commit comments

Comments
 (0)