I want to use redis as caching for my database. I wrote the following code and it is giving me the error:
const offerData = await client.getAsync(offerID) ^ TypeError: client.getAsync is not a function
My current code :
const redis = require('redis')
// Connect to the Redis server
const client = redis.createClient()
client.on('connect', () => {
console.log('[PASS]'.green + ' Redis Connected')
require('bluebird').promisifyAll(redis)
})
router.get('/', async (req, res) => {
const offerData = await client.getAsync(offerID)
let link
if (offerData) {
// If the offer data is in Redis, parse it and assign it to the link variable
link = JSON.parse(offerData)
} else {
// If the offer data is not in Redis, get it from the database and store it in Redis
link = await Offers.findOne({_id: offerID})
if (link == null) return res.sendStatus(404)
client.set(offerID, JSON.stringify(link))
}
//Do some
})
How can I fix this? Tried that promisifyAll but no luck
getAsyncin the docs. Why do you assume it exists?