標籤:bar color 用法 create string nod str 需要 blog
有段時間沒寫關於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組件的使用