in lib/redis.js [89:146]
exports.set = function(server, records, callback) {
var parts = server.split(":");
var query = ["MSET"];
records.forEach(function(record) {
query.push(record.key);
query.push(record.data);
});
var content = null;
try {
content = serialize(query);
} catch(e) {
console.error("Error occured while preparing Redis command:", e);
callback(new Error("Error occured while sending item to Redis: " + e));
return;
}
var response = "";
// Send first command to the server
var client = net.connect({ host: parts[0], port: parts[1] }, function() {
client.write(content);
});
client.setTimeout(config.timeout);
client.setEncoding('utf8');
// Wait for response line
client.on('data', function(chunk) {
response = response + chunk;
var index = response.indexOf("\r\n");
if(index != -1) {
// We have an answer
client.end();
var result = deserialize(response);
if(result != "OK") {
console.error("Error occured while sending item to Redis:", result);
callback(new Error("Error occured while sending item to Redis: " + result));
} else {
callback(null);
}
}
});
client.on('timeout', function() {
client.removeAllListeners();
client.end();
client.destroy();
console.error("Timeout occured when storing data in Redis");
callback(new Error("Timeout occured when storing data in Redis"));
});
client.on('error', function(err) {
console.error("Error occured when storing data in Redis:", err);
callback(new Error("Error occured when storing data in Redis: " + err));
});
}