Node.js與Sails~redis組件的使用

來源:互聯網
上載者:User

標籤: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組件的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.