Posts

Showing posts with the label redis

how to wait till the response is received from redis in node?

how to wait till the response is received from redis in node? I am new to node and redis.I am using redis in my node application.I want to retreive data from redis in a synchronous fashion.Here is what I tried. var redis = require("redis"), client = redis.createClient(); client.set('key',10,redis.print); function getfn1(key){ client.get(key,function(err,reply){ if(err){ console.log('Response from getfn1:-'); console.log(err); return; } console.log('Response from getfn1:-'); console.log(reply); }); } async function getfn2(key){ let response = await client.get(key); console.log('Response from getfn2:-'); console.log(response); } console.log('1'); getfn1('key'); console.log('2'); getfn2('key'); console.log('3'); The result is as follows: 1 2 3 Response from getfn2:- false Response from getfn1:- 10 As you can see I am tryi...