1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/docs/scan-iterators.md
2023-06-28 11:40:55 -04:00

980 B

Scan Iterators

⚠️ The scan iterators API in v5 has breaking changes from the previous version. For more details, refer to the v4-to-v5 guide.

SCAN results can be looped over using async iterators:

for await (const keys of client.scanIterator()) {
  const values = await client.mGet(keys);
}

This works with HSCAN, SSCAN, and ZSCAN too:

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:

client.scanIterator({
  cursor: 0, // 0 by default
  TYPE: 'string', // `SCAN` only
  MATCH: 'patter*',
  COUNT: 100
});