node.js - Async operations on redis message -


i trying update mongoose model when redis client publishes message.

this i'm doing work

redisclient.on('message', (channel, message) => { let data=  json.parse(message);  console.log(message);  let user_id = data.user_id; let story_id = data.story_id;  let ratingdetails = data.ratingdetails;  user.findbyid(user_id, (err, user) => {     if(err) return console.error(err);      user.rating += (ratingdetails.polarity * ratingdetails.rating);      console.log(ratingdetails);      console.log(user.rating);      user.save((err) => {         if(err) return console.error(err);     }); });  story.findbyid(story_id, (err, story) => {     if(err) return console.error(err);      story.totalrating += (ratingdetails.polarity * ratingdetails.rating);      story.save((err) => {         if(err) return console.error(err);     }); }); 

});

console.log(message) showing passed message isn't performing mongoose operations. models aren't being updated.

i'm using redis first time. approach or there other alternative ?

i've got solution, doing redis stuff in node process, mongo connection wasn't available in redis process.

i created connection in redis process , solved problem.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -