简体   繁体   English

转换redis密钥时的内存管理

[英]Memory management when converting redis keys

I need to convert keys from type string to hash. 我需要将键从类型字符串转换为哈希。 The name of all keys is in the set list:of:keys . 所有键的名称都在set list:of:keys

My current implementation looks like this: 我目前的实现如下:

var rdbc = require("redis").createClient(6379, '127.0.0.1');
rdbc.smembers("list:of:keys", function(err, strings){
    strings.forEach(function(string, index, strings){
        rdbc.get(string, function(err, result){
            rdbc.del(string);
            rdbc.hset(string, "foo", result);
        });
    });
});

My attempt works. 我的尝试有效。 But when list:of:keys contains many values memory usage grows a lot. 但是当list:of:keys包含很多值时,内存使用量会增长很多。

  1. Are there memory efficient structures to go through many keys? 是否有内存高效的结构可以通过许多键? (especially strings.forEach(… seems inefficient) (特别是strings.forEach(…似乎效率低下)

  2. How do I inform the garbage collector in node.js to clean up after each rdbc.del/rbdc.hset operation? 在每次rdbc.del/rbdc.hset操作后,如何通知node.js中的垃圾收集器清理?

  1. I don't know how the redis driver for node.js handles this, but if they are clever they use some the cursors redis offers to loop through the results. 我不知道node.js的redis驱动程序如何处理这个问题,但如果它们很聪明,他们会使用redis提供的一些游标来遍历结果。 This means the do not fetch all results at the beginning, they fetch them when you access them. 这意味着不要在开始时获取所有结果,而是在访问它们时获取它们。

  2. The garbage collection is handled by the V8 (the underlying JavaScript engine of node.js) There is plenty of documentation on how it works (just search for "Garbage Collection V8"): 垃圾收集由V8(node.js的底层JavaScript引擎)处理。有大量关于它如何工作的文档(只搜索“垃圾收集V8”):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM