我正在尝试使用Redis为我的应用程序缓存数据。我将数据存储在Redis中,例如:
const result = await exec.apply(this,arguments);
client.set(key,JSON.stringify(result));
,然后将缓存的数据用于以下应用程序:
const cachedValue = await client.get(key);
if(cachedValue){
const doc = JSON.parse(cachedValue);
return Array.isArray(doc) ? doc.map(d => new this.model(d)) : new this.model(doc)
}
使用new this.model
将缓存的数据转换为猫鼬文档模型。对于单个对象和对象数组,它可以正常工作,但对于嵌套对象(例如,
{
"attendance": {
"classesHeld": 0,
"classesTaken": 0,
"classesLeft": 0,
"date": {
"$date": "2018-10-30T14:37:21.596Z"
}
},
"GPA": 0,
"date": {
"$date": "2018-10-30T14:37:21.596Z"
},
"_id": {
"$oid": "5bd86ca19ffc0feb81434ac3"
},
"name": "OOC & Programming",
"code": "SE-201",
"ch": 4,
"teacher": "ada",
"semester": "Second"
}
该问题的可能解决方案是什么?预先感谢