When you are working with business applications, it's sometimes need to cache the data. At this point Redis can be very useful, it can be used as database or cache database. You can store any kind of data like strings, JSON objects etc. in Redis.
Problem we face while working with NodeJs and Redis, get data operation from Redis is Asynchronous operations so it gives you callback and your code execution will continue. This may create a problem when you want to handle it in Synchronous way. For example you may have loops inside that you are trying to access data from Redis.
In this blog I am going to explain how you can have Synchronous operations. In nutshell we got to promisify the redis module.
There is a library called bluebird, that can be used for this. Lets go step by step.
Install bluebird and redis in your NodeJs app.
npm install bluebird
npm install redis
Import it in NodeJs app.
var redis = require('redis');
var bluebird = require("bluebird");