1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

fix scan iterators

This commit is contained in:
Leibale
2023-07-06 11:37:56 -04:00
parent cffefd0337
commit 172d329234
2 changed files with 10 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ You can override the default options by providing a configuration object:
```typescript ```typescript
client.scanIterator({ client.scanIterator({
cursor: 0, // 0 by default cursor: '0', // optional, defaults to '0'
TYPE: 'string', // `SCAN` only TYPE: 'string', // `SCAN` only
MATCH: 'patter*', MATCH: 'patter*',
COUNT: 100 COUNT: 100

View File

@@ -437,19 +437,21 @@ describe('Client', () => {
// }, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('scanIterator', async client => { testUtils.testWithClient('scanIterator', async client => {
const promises = [], const entries: Array<string> = [],
keys = new Set(); keys = new Set<string>();
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
const key = i.toString(); const key = i.toString();
keys.add(key); keys.add(key);
promises.push(client.set(key, '')); entries.push(key, '');
} }
await Promise.all(promises); await client.mSet(entries);
const results = new Set(); const results = new Set();
for await (const keys of client.scanIterator()) { for await (const keys of client.scanIterator()) {
results.add(...keys); for (const key of keys) {
results.add(key);
}
} }
assert.deepEqual(keys, results); assert.deepEqual(keys, results);
@@ -465,7 +467,7 @@ describe('Client', () => {
const results: Record<string, string> = {}; const results: Record<string, string> = {};
for await (const entries of client.hScanIterator('key')) { for await (const entries of client.hScanIterator('key')) {
for (const [field, value] of entries) { for (const { field, value } of entries) {
results[field] = value; results[field] = value;
} }
} }
@@ -512,7 +514,7 @@ describe('Client', () => {
} }
} }
assert.deepEqual(members, results); assert.deepEqual(map, results);
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
// describe('PubSub', () => { // describe('PubSub', () => {