1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

some docs

Co-authored-by: Guy Royse <guy@guyroyse.com>
This commit is contained in:
Leibale
2023-06-07 11:32:15 -04:00
parent 8ef0e47e57
commit eb47bb03fc
3 changed files with 89 additions and 5 deletions

29
docs/scan-iterators.md Normal file
View File

@@ -0,0 +1,29 @@
# Scan Iterators
> :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).
[`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):
```typescript
for await (const keys of client.scanIterator()) {
const values = await client.mGet(keys);
}
```
This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
```typescript
for await (const entries of client.hScanIterator('hash')) {}
for await (const members of client.sScanIterator('set')) {}
for await (const membersWithScores of client.zScanIterator('sorted-set')) {}
```
You can override the default options by providing a configuration object:
```typescript
client.scanIterator({
TYPE: 'string', // `SCAN` only
MATCH: 'patter*',
COUNT: 100
});
```