Skip to content

Commit

Permalink
docs(README): mention duplicate keys in scan stream example (#681)
Browse files Browse the repository at this point in the history
* Mention duplicate keys in scan stream example

I've used a Set to handle the deduplication in the example, but I can switch it to a plain old object as I wrote in the comment if that feels less out of place.

* Removing storage of keys

Storing the keys as they are scanned can lead to an explosion of memory usage in a real-world application, and clashes with the philosophy of using a stream to explore the keys.

Close #678
  • Loading branch information
philraj authored and luin committed Aug 7, 2018
1 parent ca58249 commit eb79e2d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,16 @@ provides a streaming interface for the `SCAN` command to make things much easier
var redis = new Redis();
// Create a readable stream (object mode)
var stream = redis.scanStream();
var keys = [];
stream.on('data', function (resultKeys) {
// `resultKeys` is an array of strings representing key names.
// Note that resultKeys may contain 0 keys.
// Note that resultKeys may contain 0 keys, and that it will sometimes
// contain duplicates due to SCAN's implementation in Redis.
for (var i = 0; i < resultKeys.length; i++) {
keys.push(resultKeys[i]);
console.log(resultKeys[i]);
}
});
stream.on('end', function () {
console.log('done with the keys: ', keys);
console.log('all keys have been visited');
});
```

Expand Down

0 comments on commit eb79e2d

Please sign in to comment.