2

I implement redis cache in node js using mongodb its working fine.but I have doubt In mongodb I have 10 records.I tried to exceute my node js code its get data from db and stored cache its working fine.suppose I deleted data from db but its not changing in redis cache.redis cache its previous 10 records there.database changes is not changing in redis cache.How to solve it.

redis.js

// var asyncRedis = require("async-redis")

// var myCache = asyncRedis.createClient()
var redis = require('redis');

const client = redis.createClient()

client.on('connect', function () {
    console.log('Redis client connected');
});

client.on('error', function (err) {
    console.log('Something went wrong ' + err);
});




function Get_Value()
{
    client.get('products', function(err,results) {
        value = results
    })
    return value
}

function Set_Value(products)
{
    client.set('products', JSON.stringify(products))

}

exports.get_value = Get_Value;

exports.set_value = Set_Value;

routes.js

data = cache.get_value()
            if(data)
            {
              res.send(data)
            }
            else{
              const r = await db.collection('Ecommerce').find().toArray();
              res.send(r)
              data = cache.set_value(r)
            }
smith hari
  • 437
  • 1
  • 11
  • 22

0 Answers0