Reputation: 99
I have problem in reading keys in Redis on Node.js and them save data to mongodb. Because the number of keys is huge ( 1.3 million), this causes JavaScript heap out of memory.
Could anyone suggest me some Node.js module to read Redis keys as stream or some other solution to this problem, so I could avoid this issue.
Thank you very much !
Upvotes: 0
Views: 2874
Reputation: 7237
ioredis
(https://github.com/luin/ioredis) does support streams.
Example with SCAN
from their readme.
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
for (var i = 0; i < resultKeys.length; i++) {
keys.push(resultKeys[i]);
}
});
stream.on('end', function () {
console.log('done with the keys: ', keys);
});
Upvotes: 2