有段時間沒寫關于NodeJs的文章了,今天也是為了解決高并發的問題,而想起了這個東西,IIS的站點在并發量達到200時有了一個瓶頸,于是想到了這個對高并發支持比較好的框架,nodeJs在我之前寫出一些文章,主要為sails框架為主,介紹了一些使用方法,今天主要說下redis組件!
項目:SailsMvc
開發工具:webstorm
語言:nodejs
框架:sails
包:redis
主要介紹幾個用法,為string,set,hash和list的使用
測試redis組件的代碼
  index: function (req, res) {    // redis 鏈接    var redis  = require('redis');    var client = redis.createClient('6379', '127.0.0.1');    // redis 鏈接錯誤    client.on("error", function(error) {      console.log(error);    });    //redis list使用    client.lpush('ok', 'Hello World!', function(error, res) {      if(error) {        console.log(error);      } else {        console.log(res);      }    });    // redis 驗證 (reids.conf未開啟驗證,此項可不需要)     client.auth("foobared");    //選數據庫,使用set結構    client.select('0', function(error){      if(error) {        console.log(error);      } else {        // set        client.set('str_key_0', '0', function(error, res) {          if(error) {            console.log(error);          } else {            console.log(res);          }        });      }    });    //使用hash結構    client.hmset("nodejs","zzl01","OK", function(error, res) {      if (error) {        console.log(error);      } else {        console.log(res);      }    });    //關閉連接    client.end();    return res.send("OK");    //return res.view("view_name",data)//view_name參數為空表示用當前的action  }以上所述是小編給大家介紹的Node.js與Sails redis組件的使用教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
新聞熱點
疑難解答