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