Node.js與Sails~redis組件的(de)使用
有段(duan)時(shi)間沒寫關于NodeJs的(de)(de)文章了,今(jin)天也是為(wei)了解決高并(bing)發的(de)(de)問(wen)題(ti),而(er)想起(qi)了這個東西,IIS的(de)(de)站點在并(bing)發量達到(dao)200時(shi)有了一(yi)(yi)個瓶頸(jing),于是想到(dao)了這個對(dui)高并(bing)發支持(chi)比較好的(de)(de)框架,nodeJs在我(wo)之前寫出一(yi)(yi)些文章,主要(yao)為(wei)sails框架為(wei)主,介紹了一(yi)(yi)些使用(yong)方法,今(jin)天主要(yao)說下redis組件!
項(xiang)目:SailsMvc
開發工(gong)具:webstorm
語言:nodejs
框架:sails
包:redis
主要介紹幾個用法,為string,set,hash和list的使用

測試redis組件的代碼
index: function (req, res) { // redis 鏈(lian)接 var redis = require('redis'); var client = redis.createClient('6379', '127.0.0.1'); // redis 鏈接錯(cuo)誤 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"); //選(xuan)數據庫(ku),使用(yong)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); } }); //關閉連接(jie) client.end(); return res.send("OK"); //return res.view("view_name",data)//view_name參數為(wei)空(kong)表示用當前的action }
我(wo)們對知(zhi)識的總結,有時(shi)候很重點!
所(suo)以,請將(jiang)你所(suo)學的東(dong)西總結起來(lai)(lai),分享起來(lai)(lai)吧!