Summary
In the actual development, it is unavoidable to operate Mysql,mongodb,redis and other data storage servers. Here's a quick introduction to how to operate Redis.
An example
The installation of Redis server is no longer introduced here, the focus is not here. Interested can be installed on their own.
For a new module, we need to install the Redis module in our project before it can be used.
Command
CNPM Install Redis
Create a new Redis.js file with the following code:
//Introducing RedisvarRedis = require ("Redis");//Create a Redis clientvarClient = Redis.createclient ("6379", "127.0.0.1");//Connection error HandlingClient.on ("Error",function(Error) {Console.log (error);});//Redis Authentication (This configuration may not be written if Redis does not have authentication enabled)Client.auth ("123456");//FindClient.select ("15",function(Error) {if(Error) {Console.log (error); } Else{Client.set ("Node_redis_key", Json.stringify ({"Name": "Wolfy", age:28}),function(Error, res) {if(Error) {Console.log (error); } Else{console.log (res); }; //operation complete, turn off Redis connectionClient.end (true); }); };});
Inquire
Summarize
The operation of Redis here only lists the additions and queries, others can try it yourself, similar methods.
[node. js] Operations Redis