2

I tried redis cache implement in node js using mongodb.I set the data in cache.but i cant get the data in cache.how to solve this issue.

cache.js

async function Get_Value(){
    let response = await client.get('products')
    console.log("_______________")
    console.log(response)

}

I got output : true

Excepted output: json data

how to get json data using cache get method

hardillb
  • 54,545
  • 11
  • 67
  • 105
smith hari
  • 437
  • 1
  • 11
  • 22

1 Answers1

1

Redis does not provide a full async await adapter for node.js so usually as a workaround people are promisifying the lib.

const { promisify } = require('util');
const getAsync = promisify(client.get).bind(client);

async function getValue(){
    let response = await getAsync("products");
}

An other approach to promisify the entire redis library you can use:

const redis = require('redis');
bluebird.promisifyAll(redis);

Now you will be able also to use the methods using async/await.

Alexandru Olaru
  • 6,842
  • 6
  • 27
  • 53