I need to use redis async functions. Currently I am using the redis library. My require ment is that in this library im using the exists function to check if a key is in redis or not. If not i'm making a DB call inside this exists function and trying to return the DB response. Here is the part of code: -
var redis = require('redis');
var client = redis.createClient(port, 'anyhost');
client.exists(obj.empId, function(err, reply) {
if (reply == 0) {
console.log('indb call');
return db.one('SELECT * FROM iuidtest WHERE empid = $1', [obj.empId])
.then(iuidtest => {
console.log(iuidtest.iuid);
return iuidtest.empid;
})
}
});
Here I am able to print the iuid value in console but not return the value from it. I read somewhere the reason maybe that I am returning value from async method db.one inside a sync method client.exists. So I tried using the redis-async library.
var asyncredis = require('async-redis');
var myCache= asyncredis.createClient(port, 'vsseacgmy13');
But here this myCache variable does not have the redis functions like exists() that were in client variable. My requirement is here to return the DB call value after checking the key in cache. Is there any way like using another lib or making this exists function async so I can return the value of DB call?