我使用mongodb在节点js中尝试了redis缓存工具。我在缓存中设置数据。但我无法获取cache.how中的数据来解决此问题。
cache.js
async function Get_Value(){
let response = await client.get('products')
console.log("_______________")
console.log(response)
}
我得到了输出:true
例外输出:json数据
如何使用缓存get方法获取json数据
Redis没有为node.js提供完整的异步等待适配器,因此通常作为一种解决方法,人们正在宣传lib。
const { promisify } = require('util');
const getAsync = promisify(client.get).bind(client);
async function getValue(){
let response = await getAsync("products");
}
另一种方法是宣传您可以使用的整个redis
库:
const redis = require('redis');
bluebird.promisifyAll(redis);
现在您还可以使用async/await
的方法。