简体   繁体   中英

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 .

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.

  1. Are there memory efficient structures to go through many keys? (especially strings.forEach(… seems inefficient)

  2. How do I inform the garbage collector in node.js to clean up after each rdbc.del/rbdc.hset operation?

  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. 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"):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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