Skip to content

Instantly share code, notes, and snippets.

@lalithmaddali
Created April 27, 2011 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalithmaddali/945441 to your computer and use it in GitHub Desktop.
Save lalithmaddali/945441 to your computer and use it in GitHub Desktop.
Is this the proper way to backpressure redis-drain? When the value for each key is 4kb then it throws JS Memory Allocation error.
var redis = require("redis"),
fs = require("fs"),
client = redis.createClient();
var glCount = 150000 ;
var j = glCount;
var curCount = 0;
var startTime = new Date;
var i = 0;
client.on("drain", function(err){
console.log('drain event emitted');
load();
console.log(client.command_queue.length);
});
load();
var offlineq = 1000;
function load(){
for(;i<glCount;i++){
if(client.command_queue.length > 1000){
break;
}
client.set("BM_" + i + "ABCDEFGHIJKLMNOPQRSTUVWXYZ","testValue",function(err){
curCount++;
if (glCount == 0){
var endTime = new Date;
console.log("Done Loading the keys took time: " + (endTime - startTime) + "ms");
client.end();
}
});
}
}
setInterval(function(){console.log(client.command_queue.length);}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment