Javascript Redis.LRANGE返回列表,但不是我需要它的方式
我在redis中存储了大量数据并对其进行缓存,然后当我需要它时,我基本上使用lrange获取数据并将其发送到我的前端。问题是当它返回数据时,它以如下格式返回数据: 但我需要按以下格式返回: 为什么lrange函数将“”放在每个对象的前面?这是当前的lrange函数:Javascript Redis.LRANGE返回列表,但不是我需要它的方式,javascript,node.js,Javascript,Node.js,我在redis中存储了大量数据并对其进行缓存,然后当我需要它时,我基本上使用lrange获取数据并将其发送到我的前端。问题是当它返回数据时,它以如下格式返回数据: 但我需要按以下格式返回: 为什么lrange函数将“”放在每个对象的前面?这是当前的lrange函数: function rangeReturn(callback) { client.lrange("Historial_Price: " + ticker, 0, -1, (err, reply) =
function rangeReturn(callback) {
client.lrange("Historial_Price: " + ticker, 0, -1, (err, reply) => {
if (!err) {
callback(reply);
} else {
console.log("Error within client.lrange in Quandl.js");
}
});
}
//If there is already data stored
if (listIsTrue) {
//Return the data to the front end
rangeReturn(function (reply) {
console.log(reply)
return res.send(reply);
});
}
迭代每个响应并使用
JSON.parse()
解析每个项目
它将作为字符串返回。尝试使用
JSON.parse(reply)代码>。这应该会将其变回一个对象。@JayHales我用JSON.parse获得了意外的标记,我假设是因为reply实际上是一个JSON数组?
function rangeReturn(callback) {
client.lrange("Historial_Price: " + ticker, 0, -1, (err, reply) => {
if (!err) {
callback(reply);
} else {
console.log("Error within client.lrange in Quandl.js");
}
});
}
var correctValues = [];
//If there is already data stored
if (listIsTrue) {
//Return the data to the front end
rangeReturn(function(reply) {
reply.forEach(value => {
correctValues.push(JSON.parse(value));
});
// Do whatever with correctValues from here on.
console.log(reply)
return res.send(reply);
});
}