【问题标题】:node.js module for reading redis key as stream用于将 redis 键读取为流的 node.js 模块
【发布时间】:2017-05-16 02:58:24
【问题描述】:

我在 Node.js 上读取 Redis 中的键时遇到问题,它们将数据保存到 mongodb。 因为键的数量很大(130 万),这会导致 JavaScript 堆内存不足。

谁能建议我一些 Node.js 模块来读取 Redis 密钥作为流或其他解决这个问题的方法,这样我就可以避免这个问题。

非常感谢!

【问题讨论】:

    标签: node.js redis stream


    【解决方案1】:

    ioredis (https://github.com/luin/ioredis) 确实支持流。

    自述文件中的SCAN 示例。

    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);
    });
    

    【讨论】:

      猜你喜欢
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 2013-04-30
      • 2015-09-12
      • 1970-01-01
      相关资源
      最近更新 更多