Node JS - Redis All Page Caghing. XML return using redis hmset() and hgetall()



 var full_url = req.protocol + '://' + req.get('host') + req.originalUrl;
    console.log("====== full_url : " , full_url);

    client.hgetall("full_url_hash", function (err, result_hash_object) {

            if ( result_hash_object != null 
            && result_hash_object[full_url] != null  
            && ( utils.undefined_check(result_hash_object ) != "" ) 
            && ( utils.undefined_check( result_hash_object[full_url] )  != "" )  ){

                console.log("full_url_hash vast cache find. Return xml page directly sending: " , full_url);
                res.set('Content-Type', 'text/xml');
                res.send(result_hash_object[full_url] );

        } else {
          //some workers and process and 

          var hmset_url = client.hmset("full_url_hash", full_url, vast3_xml);
           if (hmset_url){
             console.log("full_url_hash adding .key : " , full_url);
           }
        res.set('Content-Type', 'text/xml');
        res.send(xml);
    }

And relational in delete , update , new controllers :

  if (client.del("full_url_hash")){
       console.log("Saved . destroy full_url_hash. ");
  }

Comments

Popular posts from this blog

Design a notification system

NETFLIX HIGH-LEVEL SYSTEM DESIGN

URL Shortener System Design