I want to store my redis data to MySQL.
My Redis data array, and each data is object.
This is what I try, but cannot save to MySQL correctly.
if (redis_headline != null) {
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "redistest"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected to MySQL!");
});
// redis isi
for (i = 0; i < redis_headline.length; i++) {
var sql = "INSERT INTO `desc` (first_name, last_name, email, phone) VALUES ('" + redis_headline[i].first_name + "','" + redis_headline[i].last_name +"','" + redis_headline[i].email + "','" + redis_headline[i].phone + "')";
con.query(sql, function (err) {
if (err) throw err;
console.log("record inserted");
});
client.flushdb( function (err, succeeded) {
console.log(succeeded + ' flush redis'); // will be true if successfull
});
// var datas =
// console.log(redis_headline[i]);
}} else {}