我已经声明了一个查询 Redis 的函数,如果在 redis 中找不到数据,则查询 SQL 数据库。以下是我的代码,它在第一行本身给出了错误。我不确定为什么作为参数的函数会导致麻烦。
function redusId(taskId, function (err, reply){
var status = taskId + ".status";
var response = taskId + ".response";
var jsonObject = {};
redisClient.get(status, function (error, reply) {
if (error) {
console.log("redis.status.ERROR: " + error);
return;
}
if (!reply) {
checkSQLdb(taskId, function (error, data) {
if(error) {
console.log("sql.ERROR", error);
}
if(!data) {
console.log("sql.status.ERROR");
}
else {
// data retrieval and posting in redis and calling redis client again
var id = data[0].id;
var status = data[0].status;
var response = data[0].response;
console.log(id, status, response);
var requestid = id + ".status";
redisClient.set(requestid, status);
requestid = id + ".response";
redisClient.set(requestid, response);
redusId(id);
}
})
}
else {
jsonObject."status" = reply;
if (reply == 1) {
//redis returns non one status no response is expected
redisClient.get(response, function(error, reply) {
if (error) {
//redis has the status but not the response
console.log("redis.response.ERROR ", error);
}
else {
jsonObject."response" = response;
return jsonObject;
}
});
}
else {
console.log("status is not one ; no response is expected");
return jsonObject;
}
}
})
});