Use of node. js with Sails~redis components

Source: Internet
Author: User

For some time did not write about Nodejs article, today is to solve the problem of high concurrency, and think of this thing, IIS site in concurrency reached 200 when there is a bottleneck, so think of this high concurrency support better framework, nodejs before I write some articles, Mainly for the sails framework, introduced a number of use methods, today the main Redis components!

Project: SAILSMVC

Development tools: Webstorm

Language: Nodejs

Frame: Sails

Package: Redis

It mainly introduces several usages for the String,set,hash and list.

To test the code for a Redis component

Indexfunction(req, res) {//Redis Links        varRedis = require (' Redis '); varClient = redis.createclient (' 6379 ', ' 127.0.0.1 '); //Redis Link ErrorClient.on ("Error",function(Error) {Console.log (error);       }); //Redis List usesClient.lpush (' OK ', ' Hello world! ',function(Error, res) {if(Error) {Console.log (error); } Else{console.log (res);              }        }); //Redis Authentication (reids.conf does not turn on authentication, this item is not required)Client.auth ("foobared"); //Select the database, use the set structureClient.select (' 0 ',function(Error) {if(Error) {Console.log (error); } Else {                //SetClient.set (' str_key_0 ', ' 0 ',function(Error, res) {if(Error) {Console.log (error); } Else{console.log (res);            }                });       }        }); //Use hash structureClient.hmset ("Nodejs", "zzl01", "OK",function(Error, res) {if(Error) {Console.log (error); } Else{console.log (res);       }        }); //Close ConnectionClient.end (); returnRes.send ("OK"); //return Res.view ("view_name", data)//view_name parameter is null for the current action}

Our summary of knowledge, sometimes very important!

So, please sum up what you have learned and share it!

Use of node. js with Sails~redis components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.