Search code examples
javascriptnode.jsexpressredisconnect-redis

Redis connection close


Im using connect-domain and connect-redis. Below code checks for redis cache in Redis database.

function redis_get(key, req, res) {
var redisClient = redis.createClient();
redisClient.get(redisKey, function (err, data) {
    if (err) {
        console.log("Error in RedisDB");
    }
    else if (data == null) {
        // Calling external function
    }
    else {
        // Calling external function
    }
    redisClient.quit();  // Not working
});

}

When cache is not avaiable Im calling external function. I want redis connection to be closed once the cache check has been done. redisClient.quit() // Not working

Any help on this will be really helpful.

Thanks


Solution

  • Below code is working fine without any problem.So check your status reply in the quit method if you get status as 'OK' means that method is working fine.

     var redis=require('redis');
     var redisClient = redis.createClient();
     redisClient.get('name', function (err, data) {
       if (err) {
          console.log("Error in RedisDB");
        }
      else if (data == null) {
          console.log('null');
         }
       else {
           console.log(data);
       }
     redisClient.quit(redis.print); 
    });